Quiz 1 ST 445 31 May 2013 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 z 4-6 ; 00004 sum = x + y + z ; 00005 cards ; 00006 220 7 00007 .25 5 00008 1.1025 00009 2 4 . 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 z ; 2. In an INPUT statement such as input X $ ?? 11-19 ; a) What do the symbols '?' or '??' control? b) What is the symbol '$' used for? c) 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_ > 3 ) then put 'inside pdv ' _n_= x= y= ; 00006 cards ; 00007 5 2 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( y > 3 ) 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 ; * two dashes ; 00014 run ; c) What would be the output if we changed line 00004 to 00004 if( y le 3 ) then output ; * le less than or equal ; d) What would be the output if we changed line 00004 to 00004 if( z > 3 ) then delete ; (Hint: yes, z doesn't appear anywhere else ) 5. a) How many observations, variables? 00001 data aid ; 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=aid min ; * 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 ; e) Suppose I submitted all 20 lines and my output window was blank, which window should I look at first? f) Suppose I submitted all 20 lines and my output window was not blank, which window should I look at first? 6. Recall reading the mileage dataset 'mazdaall.dat' with 11 records. /* class assignment #2, summer 2013 */ /* */ options ls=80 ; * easy to use with vi ; data a ; infile 'mazdaall.dat' ; input mondayr gas price total prevod currod ; if( abs(total - gas*price) gt .002 ) then put 'cheated****' ; midriven = currod - prevod ; mileage = midriven/gas ; empty = (gas > 15) ; * was the tank nearly empty? ; run ; /* now some procs */ proc print data=a ; title 'John''s new Mazda 6' ; title2 'mileage data' ; run ; /*bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb*/ proc means data=a mean var stderr ; var mileage ; title2 'statistics by tankful' ; run ; /*cccccccccccccccccccccccccccccccc*/ proc means data=a sum ; var gas midriven ; title 'Overall summary -- find mileage by hand' ; run ; a) How many observations, variables? b) What is the title of the first PROC MEANS? c) What is the title of the second PROC MEANS? 8. Which of the following produced the picture below? A. proc chart data=a ; vbar empty / sumvar=mileage type=mean ; title 'does an empty tank make a difference?' ; run ; B. proc chart data=a ; hbar empty / sumvar=mileage type=sum discrete ; title 'does an empty tank make a difference?' ; run ; C. proc chart data=a ; hbar empty / sumvar=mileage type=mean ; title 'does an empty tank make a difference?' ; run ; does an empty tank make a difference? 4 19:24 Wednesday, May 29, 2013 empty mileage Midpoint Freq Mean | 0.0 |*********************************************** 3 23.25310 | 0.3 | 0 0.00000 | 0.6 | 0 0.00000 | 0.9 |************************************************** 8 25.10245 | ----+---+---+---+---+---+---+---+---+---+---+---+-- 2 4 6 8 10 12 14 16 18 20 22 24 mileage Mean