/* module 3: problems 1a, 4, 6 */ /* 3.1a */ filename china 'China#1.dat'; *compute year-to-year change in exports; data one; infile china; input year 1-4 gross 6-10 exports 12-16 imports 18-22; d_export = exports - lag(exports); run; proc print data=one; run; /* 3.4 */ * ammendment: don't need to output to file. (already done); data two; input flavor $ 1-12 height 14-17 brand $ 19-31; datalines; Devil's food 39.0 Duncan Hines Devil's food 36.5 Duncan Hines White 30.5 Duncan Hines White 34.5 Duncan Hines Yellow 37.0 Duncan Hines Yellow 35.0 Duncan Hines ; run; data three; input flavor $ 1-12 height 14-17 brand $ 19-31; datalines; Yellow 35.5 Betty Crocker Yellow 36.0 Betty Crocker Devil's food 35.5 Betty Crocker Devil's food 37.5 Betty Crocker White 32.5 Betty Crocker White 32.5 Betty Crocker ; run; filename cakecat 'cakes.txt'; filename cakemerg 'cakes2.txt'; data cakes; set two three; file cakecat; put @1 flavor @14 height @19 brand; run; proc print data=cakes; run; data four; /* rename variables to keep through match merge */ set three; height2 = height; brand2 = brand; run; proc sort data=two; by flavor; run; proc sort data=four; by flavor; run; data cakesm; merge four two; /* dataset four listed first for proper merge */ by flavor; file cakemerg; put @1 flavor @14 height @19 brand @33 height2 @38 brand2; run; proc print data=cakesm; run; /* 3.6 */ * use only propane, internet service, and home security system in input from file; filename moonlake 'moonlake.dat'; data five; infile moonlake firstobs=26 obs=50; input propane 1 internet 9 homesec 10; run; data six; infile moonlake firstobs=251 obs=300; input propane 1 internet 9 homesec 10; run; data fivesix; set five six; run; proc print data=fivesix; run;