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 *23456 ruler ; 00002 data a ; 00003 input x 1-2 y 3-4 ; 00004 diff = x - y ; 00005 cards ; 00006 602 00007 1.20 00008 .75 00009 4 2 00010 ; 00011 proc print data=a ; 00012 run ; c) What would the output be if I changed the input statement to 00003 input x y ; 2. In an INPUT statement such as input X $ ?? 11-19 ; a) What is the symbol '$' used for? b) What does '11-19' denote? 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( y = 0 ) then x = x + 1 ; 00005 if( _n_ > 2 ) then delete ; 00006 put 'peek at the pdv ' _n_= x= y= ; 00007 cards ; 00008 2 1 00009 4 0 00010 8 4 00011 10 0 00012 ; 00013 proc print data=b ; 00014 title 'output means control' ; 00015 run ; c) What would the "put" statement produce and where would you see its results? 4. a) How many observations, variables? b) What is the output from this SAS program? 00001 data c ; 00002 input x y ; 00003 count = _n_ ; 00004 if( x = 10 ) then delete ; 00005 cards ; 00006 10 2 00007 5 4 00008 6 1 00009 10 0 00010 ; 00011 run ; 00012 proc print data=c ; 00013 var y--count ; 00014 run ; c) What would be the result if we changed line 00004 to 00004 if( z = 10 ) then delete ; (Hint: yes, z doesn't appear anywhere else ) 5. a) How many observations, variables? 00001 data reg ; 00002 input year foraid pres $ ; 00003 label foraid='foreign aid' pres='president' ; 00004 cards ; 00005 1961 4.24 Kennedy 00006 1962 4.53 Kennedy 00007 1963 5.06 Kennedy 00008 1964 4.92 Johnson 00009 1965 5.05 Johnson 00010 1966 5.05 Johnson 00011 1967 6.67 Johnson 00012 1968 6.74 Johnson 00013 ; 00014 run ; 00015 proc means data=reg max ; * one statistic ; 00016 class pres ; 00017 var foraid ; 00018 title 'Foreign aid by president' ; 00019 title2 "in the 1960's" ; 00020 run ; b) What is the output produced by PROC MEANS? c) Why do you think I used double quotes in 00019 instead of single? d) What would happen if I changed to the following statement? 00016 by pres ; 6. Use file 'wintreer.dat'.it has 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 ; 7. Use 'salary.dat' file in the class website which has 27 records, and look 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?