/***************************************************************************************************************** SAS file name: Format_Lookup File location: _________________________________________________________________________________________________________________ Purpose: To demonstrate how to perform a simple format lookup in SAS. Author: Peter Clemmensen Creation Date: 01/04/2017 This program supports the example page "SAS Format Lookup Example" on SASnrd.com *****************************************************************************************************************/ /* Example data */ data employees(drop=i); length empid $20; array first_names{20} $15 _temporary_ ("Paul", "Allan", "Thomas", "Michael", "Chris", "David", "John", "Jerry", "James", "Robert", "William", "Richard", "Bob", "Daniel", "Paul", "George", "Larry", "Eric", "Charles", "Stephen"); array last_names{20} $15 _temporary_ ("Smith", "Johnson", "Williams", "Jones", "Brown", "Miller", "Wilson", "Moore", "Taylor", "Hall", "Anderson", "Jackson", "White", "Harris", "Martin", "Thompson", "Robinson", "Lewis", "Walker", "Allen"); call streaminit(123); do i=1 to 50e6; first_name=first_names[ceil(rand("Uniform")*20)]; last_name=last_names[ceil(rand("Uniform")*20)]; empid=compress(uuidgen(), '-'); output; end; run; proc surveyselect data=employees out=temp(keep=empid) seed=123 noprint method=srs sampsize=500000; run; data emphours; set temp; hours=round(rand('Uniform', 10, 100), 0.01); run; proc datasets lib=work nolist; delete temp; run;quit; /* Sort-Merge Approach */ proc sort data=employees; by empid; run; proc sort data=emphours; by empid; run; data SortMerge; merge employees emphours; by empid; run; /* Format Lookup Approach */ data fmt; set emphours(rename=(empid=start hours=label)) end=eof; retain fmtname "HourFmt" type "c"; output; if eof then do; start=""; Label=""; HLO="O"; output; end; run; proc format library=work cntlin=fmt; run; data want; set employees; hours=input(put(empid, $HourFmt.), 10.2); run;