Sie sind auf Seite 1von 3

Exercises for PC SAS Class

Lets try a couple of exercises to practice using SAS. Ill do the first one with you, and
then you can try the second one your own.
We will use a data set called gallup.txt. The data, a data codebook, and a description of
the data can be found by clicking on !atasets" at the course web site#
http#$$www.andrew.c%u.edu$course$&'(&')$index.ht%.
*lease see the acco%panying handout for the data description and +ariable definitions.
,or %ore infor%ation on how to perfor% each of the steps, the page nu%bers
corresponding to the *- SAS." handout are referenced in parentheses.
Exercise 1.
/. 0et the AS-II data gallup" fro% the course web site and un1ip it. 2p. 34
5. Start SAS 2p. 64
6. 7ring the gallup.txt data into SAS and sa+e the data as a per%anent SAS data set
called c#8users8gallup.sd5. 2pp. 9(:4
Remember# ;ou will need to create a libna%e and filena%e before the data state%ent.
9. !isplay the contents of your data file. 2p. /'4
3. !isplay the descripti+e statistics of all of the +ariables. 2pp. //(/54
). !isplay the descripti+e statistics of age, e%ploy%ent status, and wage. 2pp. //(/54
:. !isplay a fre<uency table of education. 2p. //4
=. !isplay one obser+ation at ti%e using *roc ,sbrowse. 2p. /64
&. -reate a new te%porary data set that contains only the +ariables age, race, gender, and
education for *ittsburgh. 2p. &(/'4
/'. !isplay the cross tabulation of race and gender for *ittsburgh obser+ations. 2p. //4
>ote your output both in the Log and ?utput windows.
Exercise 2.
Write one SAS progra% to do all of the following#
/. 7ring in SAS data set c#8users8gallup.sd5 into a new te%porary data set. !rop the
obser+ations that ha+e a salary of '. 2p. :, /'4
5. -reate a du%%y +ariable that takes on the +alue / an indi+iduals salary is greater
than @5',''' and e<uals ' otherwise. 2p. =4
6. !isplay the %ean age for high and low inco%e indi+iduals. To do this, you %ust first
sort by your salary du%%y +ariable. 2p. /54
9. !isplay a fre<uency distribution of your du%%y +ariable. 2p. //4
3. Asti%ate a si%ple and a %ultiple regression where salary is the dependent +ariable.
Bse the explanatory +ariables of your choice. 2p. /54
>ow run the progra%. If there are any errors, do your best to try to debug.
Example Solutions Program for Exercise 1.
/* e:\classes\90906\sasws\ex1.sas performs the tasks in exercise 1*/
/* by Rob Greenbam*/
/* !ate 1/1"/1999*/
libname sers #c:\sers\#$
filename %alltxt #e:\classes\90906\%allp.txt#$
/* &. 'rin% in the ascii !ata an! sa(e as c:\sers\%allp.s!) */
!ata sers.%allp$
infile %alltxt$
inpt location a%e race %en! e!c emp wa%e hors weeks salary income
!isloc train month rate$
/* *. !isplay contents*/
+R,- -,./0./1 !ata2 sers.%allp$
/* 3. !escripti(e stats of all (ariables*/
+R,- 405.1 !ata 2 sers.%allp$
/* 6. 6isplay the !escripti(e statistics of a%e7 employment stats7 an!
wa%e. */
+R,- 405.1 !ata 2 sers.%allp$
(ar a%e emp wa%e$
/* ". 6isplay a fre8ency table of e!cation. */
+R,- 9R0: !ata 2 sers.%allp$
tables e!c$
/* ;. 6isplay one obser(ation at a time: */
+R,- 91'R,<10 !ata 2 sers.%allp$
/* 9. -reate a new temporary !ata set that contains only
the (ariables a%e7 race7 %en!er7 an! e!cation for +ittsbr%h.*/
65/5 +itt =keep 2 a%e race %en! e!c>$
set sers.%allp$
if location 2 6$
/* 10. 6isplay the cross tablation of race an! %en!er for +ittsbr%h
obser(ations. */
+R,- 9R0: !ata 2 pitt$
tables race*%en!$
rn$
Example Solutions Program for Exercise 2.
/* e:\classes\90906\sasws\ex).sas performs the tasks in exercise )*/
/* by Rob Greenbam*/
/* !ate 1/1;/1999*/
libname sers #c:\sers\#$
/* 1. 'rin% in 151 !ata set c:\sers\%allp.s!) into a new temporary
!ata set.
6rop the obser(ations that ha(e a salary of 0. */
65/5 temp!at$
set sers.%allp$
if salary 2 0 then !elete$
/* ). -reate a !mmy (ariable that takes on the (ale 1 an in!i(i!al#s
salary
is %reater than ?)07000 an! e8als 0 otherwise. */
if salary @)0000 then bi%sal 2 1$
else bi%sal 2 0$
/* &. 6isplay the mean a%e for hi%h an! low income in!i(i!als. /o !o
this7 yo mst first sort by yor salary !mmy (ariable. */
/* first sort */
+R,- 1,R/ !ata 2 temp!at$
by bi%sal$
/* now !o the means */
+R,- 405.1 !ata 2 temp!at$
(ar a%e$
by bi%sal$
/* *. 6isplay a fre8ency !istribtion of yor !mmy (ariable. */
+R,- 9R0: !ata 2 temp!at$
tables bi%sal$
/* 3. 0stimate a simple an! a mltiple re%ression where salary is the
!epen!ent (ariable. Ase the explanatory (ariables of yor choice. */
+R,- R0G !ata 2 temp!at$
mo!el salary 2 e!c$
mo!el salary 2 e!c !isloc train$
rn$

Das könnte Ihnen auch gefallen