* A simple one-dimensional array example; DATA tests; INPUT student $ math english history science; ARRAY curves[*] math--science; ARRAY curvedscore[5] _temporary_; *compare to next approach; *ARRAY curvedscore[4] curvedmath curvedeng curvedhist curvedsci; DO i=1 to dim(curves); curvedscore[i] = (100**.2)*(curves[i]**.8); if curvedscore[i] ge 90 then HighPassCount+1; else if curvedscore[i] ge 70 then PassCount+1; else FailCount+1; END; DROP i; datalines; Jones 45 56 76 65 Smith 78 92 88 67 Turner 56 59 65 44 Thomas 84 74 85 66 Walker 92 91 85 77 ; run; PROC PRINT data=tests; run; * Variation on simple one-dimensional array example; * This tracks the counts of passes and fails differently; DATA tests; INPUT student $ math english history science; ARRAY curves[*] math--science; ARRAY curvedscore[7] curvedmath curvedeng curvedhist curvedsci HighPassCount PassCount FailCount; curvedscore[5]=0;curvedscore[6]=0;curvedscore[7]=0; *resets counts before each observation is read; DO i=1 to dim(curves); curvedscore[i] = (100**.2)*(curves[i]**.8); if curvedscore[i] ge 90 then curvedscore[5]+1; else if curvedscore[i] ge 70 then curvedscore[6]+1; else curvedscore[7]+1; END; DROP i; datalines; Jones 45 56 76 65 Smith 78 92 88 67 Turner 56 59 65 44 Thomas 84 74 85 66 Walker 92 91 85 77 ; run; PROC PRINT data=tests; run; *Lookup table example; data one; input score age; array answer {13:15,1:5} _temporary_ (4 5 5 5 5 3 4 5 5 5 2 3 4 5 5); adjusted = answer(age,score); datalines; 5 13 5 15 4 13 5 14 1 13 2 15 1 14 3 15 4 14 3 15 ; run; proc print; run; *Lookup table with 3-dimensional array; data inputdata; input sex $ score age; *The last two rows should generate different adjusted scores; datalines; M 5 13.5 F 5 13.5 M 4 12.5 M 5 13.0 F 1 12.5 F 2 13.5 M 1 13.5 F 3 13.5 F 4 13.0 M 3 13.5 F 2 12.5 M 2 12.5 ; run; proc format; invalue gender 'F'=1 'M'=2; invalue age 12.5=1 13.0=2 13.5=3; data one; set inputdata; array answer {1:2,0:3,0:6} _temporary_ (1 1 2 3 4 5 . 1 4 4 5 5 5 12.5 1 3 4 4 5 5 13.0 1 2 3 4 4 5 13.5 2 1 2 3 4 5 . 2 4 5 5 5 5 12.5 2 3 4 5 5 5 13.0 2 2 3 4 5 5 13.5); adjusted=answer(input(sex,gender.), input(age,age.),score); proc print; run; *Stored lookup table; data lookup; input age adjscore1-adjscore5; datalines; 13 4 5 5 5 5 14 3 4 5 5 5 15 2 3 4 5 5 ; run; data two; input score age; datalines; 5 15 5 15 4 13 5 14 1 13 2 15 1 15 3 15 4 14 3 15 ; run; data twoadj (keep=age score finalscore); array adj{13:15,5} _temporary_; if _n_=1 then do i=1 to 3; set lookup; array adjscore{*} adjscore1-adjscore5; do j=1 to dim(adjscore); adj{age,j}=adjscore{j}; end; end; set two; finalscore=adj{age,score}; run; proc print; run; *PROC TRANSPOSE example; *Read in the table and convert it to long format; data agechart; input length weight1-weight5; datalines; 1 1 1 . . . 2 1 2 2 3 . 3 . 2 3 3 4 4 . . 3 4 4 5 . . 3 4 5 ; proc sort data=agechart; by length; proc transpose data=agechart out=tchart (rename=(age1=age)) name=weight prefix=age; by length; run; proc print; run; *Rename variables and modify their types; data fchart; set tchart; weightc=substr(weight,7,1); ww=input(weightc,1.); drop weight weightc; run; proc print; run; *Read in data; proc format; invalue weight low - 900 = 1 901 - 1300 = 2 1301 - 2000 = 3 2001 - 2500 = 4 2501 - high = 5; invalue length low - 400 = 1 401 - 500 = 2 501 - 600 = 3 601 - 675 = 4 676 - high = 5; run; data striper; input id TL WW; length=input(tl,length.); ww=input(ww,weight.); datalines; 1 523 1340 2 535 1297 3 397 1020 4 615 2115 ; run; proc print; run; *Merge data sets; proc sort data=striper; by length ww; proc sort data=fchart; by length ww; run; data striper_age; merge striper(in=in_s) fchart; by length ww; if in_s; run; proc print; run;