*Overlapping formats; proc format; value age (multilabel) 15-29="below 30" 15-19="15 to 19" 20-29="20 to 29"; data age; input age books @@; cards; 15 13 20 13 25 22 ; proc means sum maxdec=0; class age/mlf; *mlf for multilabel format; format age age.; var books; run; * Similar to Book example; proc format; value dates (multilabel) '01JAN1988'd - '31MAR1988'd = '1st quarter' '01APR1988'd - '30JUN1988'd = '2nd quarter' '01JUL1988'd - '30SEP1988'd = '3rd quarter' '01OCT1988'd - '31DEC1988'd = '4th quarter' '01JAN1988'd - '30JUN1988'd = 'First Half of Year' '01JUL1988'd - '31DEC1988'd = 'Second Half of Year'; run; data citiday; set sashelp.citiday; collection_date=date; run; proc tabulate data=citiday out=japantab format = dollar9.2; format collection_date dates.; class collection_date / mlf; var DSIJPND; table collection_date, DSIJPND*(mean median); run; /*Just print last 6 obs*/ %let dsid=%sysfunc(open(japantab)); %let num=%sysfunc(attrn(&dsid,nlobs)); %let rc=%sysfunc(close(&dsid)); %let number = 6; data last6; set japantab (firstobs = %eval(&num.-&number.+1)); run; proc print data=last6; var collection_date DSIJPND_Mean DSIJPND_Median; format DSIJPND_Mean dollar9.2 DSIJPND_Median dollar9.2; run; *PICTURE statements with digit selectors; proc format; picture montha 1-12='99'; picture monthb 1-12='00'; picture monthc 1-12='11'; *Same as montha; data months; input jan oct; datalines; 1 10 ; proc print; format jan oct montha.; run; proc print; format jan oct monthb.; run; *PICTURE statements with message characters; proc format; picture millA low-high = '009.9M' (mult=.00001); *mult control significant digits; picture millB low-high = '009.9M' (prefix='$' mult=.00001); picture millC (round) low-high = '009.9M' (prefix='$' mult=.00001); data numbers; input @1 A @1 B @1 C; datalines; 12500000 1000000 1450000 900000 ; proc print; var a b c; format a milla. b millb. c millc.; run; proc format; *'30 days' doesn't work; * <- excludes the lower limit, not the upper limit; * -< excludes the upper limit, not the lower limit; picture tempfcst low-72 = '00.0 F (below average for next 30 days)' 72<-75 = '00.0 F (normal for next thirty days)' 75<-high = '00.0 F (above average for next thirty days)'; data ag_forecast; input county :$9. forecast; datalines; aiken 72 florence 75 sumter 73 ; proc print data=ag_forecast; var county forecast; format forecast tempfcst.; run; *Create a different format library; *libname form541 'f:\STAT 541\sas formats'; *run; *PICTURE statements with directives; proc format; picture dt low-high = 'TIME STAMP: %A %B %d, %Y.' (datatype=date) ; picture tm low-high = '%I:%0M:%S %p' (datatype=time); run; *Note the interesting coding here; *SAS won't find the formats; data _null_; file print; now = today(); tm = time(); put now dt33. tm tm.; run; *SAS can find the stored formats; options fmtsearch=(work.formats); data _null_; file print; now = today(); tm = time(); put now dt33. tm tm.; run; proc format fmtlib; select dt tm; *Note that default length of 25 for dt is too short; run; /* Example with citiday data */ data citiday; set sashelp.citiday; collection_date=date; run; proc format; picture mydate low-high='%0d-%b, %Y ' (datatype=date); run; proc print data=citiday (keep = date collection_date obs=20); format collection_date mydate12.; run; *Copy formats from one catalog to another; proc catalog catalog=form541.formats; copy out=work.formats; select dt.format; run; proc catalog cat=work.formats; contents; run; *Save a format as a data set; proc format cntlout=outform; value $gender "M"="male" "F"="female"; run; proc print data=outform; run; proc contents data=outform; run; ********************************************************; * CNTLIN example similar to book example; * Using CNTLIN; data acities1; input city :$10. code :$11. name :$24. country :$11.; datalines; Auckland AKL International New_Zealand Amsterdam AMS Schiphol Netherlands Anchorage ANC Anchorage_International USA Stockholm ARN Arlanda Sweden Athens ATH Hellinikon_International Greece Birmingham BHM Birmingham_International USA Bangkok BKK Don_Muang_International Thailand ; run; data aports1; keep Start Label FmtName; retain FmtName '$airport'; set acities1 (rename=(Code=Start City=Label)); run; proc format cntlin=aports1; run; proc format fmtlib; select $airport; run; data cargo1; input origin $ dest $ cargorev; datalines; AKL ARN 111720 BHM BKK 109270 ANC BHM 109270 ARN AMS 116130 ATH ANC 108290 ; run; proc print data=cargo1; var origin dest cargorev; format origin dest $airport.; run; ***********************************************; *Chapter 17 Supplement and Review code; *Taken from Chapter 17 Supplement; *Alternative to IF-THEN-ELSE processing for formats; data one; length teacher counselor $30.; input rating $20.; select (rating); when ('Exemplary') teacher='Frodo'; when ('Poor','Fair') do; teacher='Aragorn'; counselor='Gandalf'; end; otherwise do; teacher='Unassigned'; counselor='Legolas'; end; end; datalines; Exemplary Poor Fair Good ; proc sql; select * from one; quit; *Keywords for INFORMATS; * Taken from Chapter 17 Review; data grades; input grade; grade=grade/10; cards; 20 25 ; proc print; run; data grades; input grade 2.1; cards; 20 25 ; proc print; run; data grades; input grade 2.1; cards; 20 30 ; proc print; run; data grades; input grade 2.1; cards; 20 30 ; proc print; format grade f12.1; run; data grades; input grade 3.2; cards; 200 300 ; proc print; format grade f4.2; run; /* Dealing with Social Security numbers as data */ data grades; input ssn; cards; 056789012 ; proc format; picture s low-high=999999999 (prefix='SSN: '); proc print; var ssn; format ssn s.; proc print; var ssn; format ssn ssn.; run; data SocNum; input ssn; cards; 99882 555556888 ; run; * Using z9. will add leading zeroes; proc print data = SocNum; format ssn z9.; run; proc format; invalue check 1,2,.=_same_ other=_error_; data one; input gender check.; datalines; 1 2 3 . ; proc sql; select * from one; quit; * Formatting with special missing value codes; data one; input x @@; datalines; .i .a . 1 0 2 ; proc sort data=one; by x; proc format; value sample 1='Yes' 0='No' .='No Response' .i='Illegible' .a='Attrition'; proc print data=one; format x sample.; run; proc print data=one; run;