Quiz 2 ST 445 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? 00001 data feet special(drop=iq) ; 00002 input iq gender $ shoesize ; 00003 output feet ; 00004 if( shoesize > 12 ) then output special ; 00005 cards ; 00006 105 f 8.5 00007 98 f 7.0 00008 114 f 10.0 00009 83 f 6.0 00010 92 m 7.5 00011 128 m 10.5 00012 97 m 13.5 00013 105 m 15.0 00014 110 m 10.0 00015 ; 00016 run ; 00017 proc means data=feet n max ; 00018 class gender ; 00019 var shoesize ; 00020 title 'Foot size and intelligence' ; 00021 run ; b) What is the output from this SAS program? Quiz 2 ST 445 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? 00001 data feet special(drop=iq) ; 00002 input iq gender $ shoesize ; 00003 output feet ; 00004 if( shoesize < 7 ) then output special ; 00005 cards ; 00006 105 f 8.5 00007 98 f 6.5 00008 114 f 10.0 00009 83 f 6.0 00010 92 m 7.5 00011 128 m 10.5 00012 97 m 13.5 00013 105 f 6.5 00014 110 m 10.0 00015 ; 00016 run ; 00017 proc means data=feet n max ; 00018 class gender ; 00019 var shoesize ; 00020 title 'Foot size and intelligence' ; 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 mx . ; 00003 input x y ; 00004 if( x > mx ) then do ; 00005 mx = x ; 00006 obs = _n_ ; 00007 end ; 00008 if( y < 0 ) then delete ; 00009 put 'max so far ' _n_ mx ; 00010 cards ; 00011 3 2 00012 17 -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?