Quiz 2 ST 445 12 June 2013 CLOSED BOOK AND NOTES NAME ____________________________ For some 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 in dataset MUSIC? b) How many observations, variables in dataset CHOIR? 00001 data music choir(drop=instr) ; 00002 input name $ age instr $ ; 00003 output music ; 00004 if( instr = 'voice' ) then output choir ; 00005 cards ; 00006 Susan 17 flute 00007 Tom 24 voice tenor 00008 Emily 38 flute 00009 Mary 46 voice soprano 00010 George 44 guitar 00011 Paul 58 guitar 00012 Elaine 55 voice alto 00013 Ellen 48 voice soprano 00014 Mark 33 trumpet 00015 ; 00016 run ; 00017 proc means data=music max ; 00018 class instr ; 00019 var age ; 00020 title 'Sgt Pepper''s Band' ; 00021 run ; b) What is the output from this SAS program? Quiz 2 ST 555 12 June 2013 CLOSED BOOK AND NOTES NAME ____________________________ For some 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 in dataset MUSIC? b) How many observations, variables in dataset ADULT? 00001 data music adult(drop=age) ; 00002 input name $ age instr $ ; 00003 output music ; 00004 if( age > 21 ) then output adult ; 00005 cards ; 00006 Susan 17 flute 00007 Tom 24 voice tenor 00008 Emily 38 flute 00009 Mary 16 voice soprano 00010 George 44 guitar 00011 Paul 18 guitar 00012 Elaine 55 voice alto 00013 Ellen 48 voice soprano 00014 Mark 33 voice bass 00015 ; 00016 run ; 00017 proc means data=music min ; 00018 class instr ; 00019 var age ; 00020 title 'Sgt Pepper''s Band' ; 00021 run ; b) What is the output from this SAS program? 2. a) How many observations, variables ? b) What is the output from this SAS program? 00001 data b; 00002 retain mn 99 ; 00003 input x y ; 00004 if( x < mn ) then do ; 00005 mn = x ; 00006 obs = _n_ ; 00007 end ; 00008 if( y < 0 ) then delete ; 00009 put 'min so far ' _n_ mn ; 00010 cards ; 00011 13 2 00012 7 4 00013 8 -3 00014 ; 00015 run ; 00016 proc print data=b ; 00017 run ; c) What would the "put" statement produce and where would you see its results? 3. a) How many observations, variables? 00001 data blinka ; 00002 input treenum @ ; 00003 do dir = 'ns', 'ew' ; 00004 input resin @ ; 00005 output ; 00006 end ; * of loop on dir ; 00007 datalines ; 00008 776 8.10 6.20 no apical dominance 00009 334 7.71 6.82 00010 287 7.90 7.40 beetle damage evident 00011 ; 00012 proc print data=blinka ; 00013 title 'Resin flow in loblolly pines' ; 00014 run ; b) Would anything change here if we changed both occurences of the single trailing @ with the double @@ ? 4. a) How many observations, variables? b) What is the output from this SAS program? 00001 data b; 00002 input x y z ; 00003 w = 0 ; 00004 if( y eq 0 ) then delete ; 00005 w = sum(x, y, z) ; 00006 cards ; 00007 2 0 w 00008 6 1 0 00009 10 2 w 00010 ; 00011 run ; 00012 proc print data=b ; 00013 run ; c) Would anything change if we rewrote 00005 as below? 00005 w = x + y + z ; 5. In some problems we have used the option dlm='09'x or dlm=','. In what statement is this option available, and why would we want to use it? 6. In the file 'consump.dat' are (old) data on US consumption from an Econometrics textbook (Kmenta, who cites Griliches). Write the code to produce a dataset with 26 observations that looks like: YEAR QUART USCNSMP ------ ------- --------- 1955 1 248.7 1955 2 253.7 1955 3 259.9 1955 4 261.8 1956 1 263.2 ... ... 1961 1 297.0 1961 2 301.6 where the file consump.dat looks like: 1955 248.7 253.7 259.9 261.8 1956 263.2 263.7 263.4 266.9 1957 268.9 270.4 273.4 272.1 1958 268.9 270.9 274.4 278.7 1959 283.8 289.7 290.8 292.8 1960 295.4 299.5 298.6 299.6 1961 297.0 301.6 . . 7. a) How many observations, variables? b) What is the output from this SAS program? 00001 data djones ; 00002 array close(4) indust transp utilit stocks ; 00003 infile 'djave.dat' firstobs=2 ; 00004 do j = 1 to 4 ; 00005 input day open high low dclose change type $ ; 00006 close(j) = dclose ; 00006 end ; 00007 keep day indust--stocks ; * just these 5 variables ; 00008 run ; 00009 proc means data=djones min ; * just the min ; 00010 title 'Data courtesy of Brad Lagle' ; 00011 title2 'Dow-Jones averages' ; 00012 run ; The file 'djav.dat' looks like: day open high low close change index 21 6839.26 6855.80 6808.08 6843.87 +4.47 INDUST 21 2314.54 2323.79 2303.14 2317.63 +5.40 TRANSP 21 239.17 239.25 237.98 238.26 -0.98 UTILIT 21 2122.09 2126.67 2113.25 2122.75 +2.32 STOCKS 22 6801.16 6894.29 6800.00 6883.90 +40.03 INDUST 22 2313.00 2344.13 2304.68 2337.35 +19.27 TRANSP 22 237.49 239.59 237.28 239.52 +1.26 UTILIT 22 2112.63 2137.61 2111.15 2136.51 +13.76 STOCKS 23 6881.20 6888.13 6814.24 6850.03 -33.87 INDUST 23 2345.37 2360.47 2337.35 2355.23 +17.88 TRANSP 23 239.31 240.85 238.89 240.85 +1.33 UTILIT 23 2137.69 2137.91 2124.82 2135.69 -0.82 STOCKS 24 6880.05 6906.60 6742.28 6755.75 -94.28 INDUST 24 2362.01 2378.86 2345.68 2348.76 -6.47 TRANSP 24 241.75 243.29 239.94 240.43 -0.42 UTILIT 24 2144.05 2154.40 2111.89 2115.58 -20.11 STOCKS c) Write a DROP statement equivalent to this KEEP statement. 00007 keep day indust--stocks ; * just these 5 variables ; d) What does FIRSTOBS=2 do in the INFILE statement?