Quiz 1 ST 445 14 February 2012 CLOSED BOOK AND NOTES NAME ____________________________ For most of the questions on this quiz, I am asking what the output will be from the SAS code. *** For each dataset created, be sure to give the number of observations and the number of variables. *** Note that the line numbers are given with the code, and remember that there's a blank column between the line numbers' field and any code or data. 1. a) How many observations, variables ? b) What is the output from this SAS program? 00001 data idle ; 00002 input name $ score rating ; 00003 total = score + rating ; * summary ; 00004 if( total eq . ) then put name ; * who's missing? ; 00005 label score="Judges' score" ; 00006 attrib rating label='Audience Score' format=2. ; 00007 cards ; 00008 Joshua 10 16 rock 00009 Ruth 9 . country 00010 Ezra 8 8 rock 00011 Eric 10 18 country 00012 George gong 20 folk/rock 00013 ; 00014 run ; 00015 proc print data=idle label ; * remember label ; 00016 var name--rating ; 00017 run ; c) What would the "put" statement produce and where would you see its results? d) Why do you think I used double quotes in 00005 instead of single? Quiz 1 ST 445 14 February 2012 CLOSED BOOK AND NOTES NAME ____________________________ For most of the questions on this quiz, I am asking what the output will be from the SAS code. *** For each dataset created, be sure to give the number of observations and the number of variables. *** Note that the line numbers are given with the code, and remember that there's a blank column between the line numbers' field and any code or data. 1. a) How many observations, variables ? b) What is the output from this SAS program? 00001 data idle ; 00002 input name $ score rating ; 00003 total = score + rating ; * summary ; 00004 if( total eq . ) then put name ; * who's missing? ; 00005 label score='Audience Score' ; 00006 attrib rating label="Judges' Score" format=2. ; 00007 cards ; 00008 Joshua 10 16 rock 00009 Ruth 9 . country 00010 Ezra 8 8 rock 00011 Eric 10 18 country 00012 George gong 20 folk/rock 00013 ; 00014 run ; 00015 proc print data=idle label ; * remember label ; 00016 var name--rating ; 00017 run ; c) What would the "put" statement produce and where would you see its results? d) Why do you think I used double quotes in 00006 instead of single? 2. Consider the following code: 00001 data feet ; 00002 input iq gender $ shoesize ; 00003 if( shoesize > 12 ) then delete ; 00004 cards ; 00005 103 m 9.5 00006 114 m 12.5 00007 83 m 10.0 00008 92 f 7.5 00009 124 f 9.5 00010 ; 00011 run ; 00012 proc means data=feet min ; 00013 class gender ; 00014 var shoesize ; 00015 title 'Intelligence and Shoe Size' ; 00016 run ; a) How many observations and how many variables are in FEET? b) What is the output from PROC MEANS? c) If I replace line 13 with 00013 by gender ; will SAS give the same results? Why or why not? d) If I replace line 3 with 00003 if( shoesize le 12 ) then output ; will SAS give the same results? Why or why not? 3. a) How many observations, variables ? b) What is the output from this SAS program? 00001 data b ; 00002 input x y ; 00003 put 'see the pdv ' x= _n_= ; 00004 if( x > 20 ) then delete ; 00005 xold = x ; 00006 cards ; 00007 21 4 00008 3 2 00009 11 00010 4 4 00010 ; 00011 run ; 00012 proc print data=b ; 00013 run ; c) Which window do I always look at first? 2. Consider the following code: 00001 data feet ; 00002 input iq gender $ shoesize ; 00003 if( shoesize > 12 ) then delete ; 00004 cards ; 00005 105 f 8.5 00006 98 f 7.0 00007 114 f 10.5 00008 83 m 6.0 00009 92 m 13.5 00010 128 m 11.5 00011 ; 00012 run ; 00013 proc means data=feet max ; 00014 class gender ; 00015 var shoesize ; 00016 title 'Shoe size and Intelligence' ; 00017 run ; a) How many observations and how many variables are in FEET? b) What is the output from PROC MEANS? c) If I replace line 14 with 00014 by gender ; will SAS give the same results? Why or why not? d) If I replace line 3 with 00003 if( shoesize le 12 ) then output ; will SAS give the same results? Why or why not? 3. a) How many observations, variables ? b) What is the output from this SAS program? 00001 data b; 00002 input x y ; 00003 output ; 00004 if( x > 10 ) then z = x + _n_ ; 00005 output ; 00006 z = 5 ; 00007 cards ; 00008 4 4 00009 12 00010 3 2 00011 ; 00012 run ; 00013 proc print data=b ; 00014 run ; c) Which window do I always look at first? 5. Recall the rosette bud data that you saw in Homework #2, where the file 'wintreer.dat' had 113 records. 00001 data a ; 00002 infile 'wintreer.dat' firstobs=2 ; 00003 input i rownum 9-10 treenum rosbud age 00004 budtop topin topterm ; 00005 if( budtop = topin + topterm ) then wrong = 0 ; 00006 else wrong = 1 ; 00007 run ; 00008 proc print data=a (obs=5) ; /* top */ 00009 title 'the beginning of the data' ; 00010 run ; 00011 proc means data=a sum ; 00012 var wrong ; 00013 title1 'Analysis of Rosette Buds on Abies Fraseri' ; 00014 title2 'data courtesy of Siobhan O''Reilly' ; 00015 run ; 00016 proc plot data=a ; 00017 plot rosbud*rownum ; 00018 title 'Infestation higher if closer to road (rownum)?' ; 00019 run ; a) How many observations, variables? b) What is the result of the proc means? c) Why did I put two quotes in Siobhan's last name (line 15) ? d) For the four procs above, what will be the titles printed for each? 00008 proc print data=a (obs=5) ; /* top */ 00011 proc means data=a sum ; 00016 proc plot data=a ; 6. Recall the 'salary.dat' file from a class exercise which had 27 records, and looked like this: 1 25.1 0 f 2 41.3 17 f 3 29.6 5 f 4 40.7 15 f ... ... ... ... 26 37.8 9 m 27 58.3 25 m a) How many observations, variables ? b) What is the output from this SAS program? 00001 data teachers ; 00002 infile 'salary.dat' ; 00003 input count sal exp gender $ ; 00004 rookie = (exp < 5) ; 00005 label sal='salary' exp='experience' ; 00006 run ; 00007 proc print data=teachers (obs=3) label ; 00008 var _character_ ; 00009 title "teachers' salary" ; 00010 run ; c) Which of the following produced the picture below? A. 00000 proc chart data=teachers ; 00000 hbar rookie ; 00000 title 'salary data' ; 00000 run ; B. 00000 proc chart data=teachers ; 00000 hbar rookie / sumvar=sal type=mean ; 00000 title 'salary data' ; 00000 run ; C. 00000 proc chart data=teachers ; 00000 vbar rookie / discrete ; 00000 title 'education data' ; 00000 run ; salary data 12 16:41 Sunday, February 12, 2012 rookie salary Midpoint Freq Mean | 0.00 |******************************************** 24 43.85417 | 0.25 | 0 0.00000 | 0.50 | 0 0.00000 | 0.75 | 0 0.00000 | 1.00 |*************************** 3 26.86667 | -----+----+----+----+----+----+----+----+---- 5 10 15 20 25 30 35 40 salary d) What option would simplify this chart?