Log to Illustrate Format Operations in SAS ========================================== (I) Formatting at Input stage: proc format ; value agedc Low- <40 = 35 40-49 = 45 50-59 = 55 60-HIGH = 65 ; value $salint 0 - 200 = "L" 201 - 300 = "M1" 301 - 400 = "M2" 401 - HIGH = "H" ; data newceo; infile "ASCdata/CEO.dat"; * in my wam ASCII data directory; input agegp salry $ ; format agegp agedc. salry $salint. ; proc print data=newceo (obs=12); run; Obs agegp salry 1 55 L 2 45 H 3 35 M1 4 45 M1 5 45 M2 6 55 H 7 45 M2 8 55 H 9 35 M1 10 45 H 11 55 H 12 55 H (II) Formatting to Re-code libname home "."; * my wam SAS-file directory ; data newceo2; infile "ASCdata/CEO.dat"; input age salry $ ; agedec = put(age, agedc.); salgp = put(salry, salint.); * NOTE: salry had to be a character variable to make this work ; proc print data=newceo2 (obs = 12); run; Obs age salry agedec salgp 1 53 145 55 L 2 43 621 45 H 3 33 262 35 M1 4 45 208 45 M1 5 46 362 45 M2 6 55 424 55 H 7 41 339 45 M2 8 55 736 55 H 9 36 291 35 M1 10 45 58 45 H 11 55 498 55 H 12 50 643 55 H data newceo3; set newceo2 (keep = AGE SALRY); agedec = put(age, agedc.); salgp = put(salry, salint.); run; * Gives the same recoded SAS dataset; (III) Formatting in PROC PRINT or FREQ proc print data = newceo2 (obs=8); var age salry; title "Formatted Print without Data-Step"; format age agedc. salry $salint. ; run; * Get same printed output from initial age and salry dataset without recoding in data-step; proc freq data=newceo2; tables salry * age / nocum norow nocol nopercent; title "Formatted Table, Recoded in FREQ"; format age agedc. salry $salint. ; run; The FREQ Procedure Table of salry by age salry age Frequency|35 |45 |55 |65 | Total ---------+--------+--------+--------+--------+ L | 0 | 1 | 3 | 2 | 6 ---------+--------+--------+--------+--------+ M1 | 3 | 5 | 8 | 3 | 19 ---------+--------+--------+--------+--------+ M2 | 2 | 6 | 4 | 1 | 13 ---------+--------+--------+--------+--------+ H | 0 | 7 | 9 | 5 | 21 ---------+--------+--------+--------+--------+ Total 5 19 24 11 59