250 likes | 349 Views
Formats to the Rescue. Gary McQuown Data and Analytic Solutions Inc. Fairfax, VA. Combining Data. MERGE. A. SQL JOIN. Key. C. B. Combining Data. INDEX. A. C. B. Combining Data. A. HASHING. C. B. Combining Data. A. B. Key W. C. FORMATS. D. Key X. Key Y. Key Z. C.
E N D
Formats to the Rescue Gary McQuown Data and Analytic Solutions Inc. Fairfax, VA.
Combining Data MERGE A SQL JOIN Key C B
Combining Data INDEX A C B
Combining Data A HASHING C B
Combining Data A B Key W C FORMATS D Key X Key Y Key Z C E G I F H J
Issues • Sorts or Index are Impractical • Many “Small” Tables • Frequently Used Process • Efficiency • Ease of Use
Formats Table lookup Associate one value with another format date date9.; 09OCT2006 format zip cityz. ; New York
put ( start , $myfmt. ) First Name, Last Name, DEA #, EIN, SSN, DOB, Specialty, Complaints, Office Address, Home Address, States Licensed, Drug Class Allowed, Sanctions, etc. Drug Names, Drug Category, Drug Class Latitude, Longitude, City, County, State
Advantages No Sorting of Primary File Sort Smaller Files Unique Start Values
Advantages Efficient (where=( put(start, $myfmt.) = “1” )) Reads only selected rows
Advantages Flexible var = put(start, $myfmt.); if put(start, $myfmt.) = “XX” format (start, myfmt.)
Advantages Reusable (library = library) Catalogs Reduces Coding (replaces if then !) Easily Update
Numeric proc format; value SexNum 1=“Male“ 0=“Female”; run; Character proc format; value $ SexChar ‘1’=“Male“ ‘0’=“Female”; run; Easy to Create
proc sort data= FOO nodupkey; by FROM_VAL; run; data MYFMT (keep = fmtname hlo label start type); retain fmtname “MYFMT” type “N”; set FOO; end = lastrec; start = FROM_VAL; label = TO_VAL; output; if lastrec then do; hlo = “O”; label = “0”; output; end; run; proc format cntlin = MYFMT library=library; run;
FMTNAME= name TYPE= “C”“N”“I”“J”“P” START=values to be converted. LABEL=values to become. HLO= “H”“L”“O”
proc sort data= FOO nodupkey; by FROM_VAL; run;
data MYFMT (keep = fmtname hlo label start type); retain fmtname “MYFMT” type “N”; set FOO; end = lastrec; start = FROM_VAL; label = TO_VAL; output;
if lastrec then do; hlo = “O”; label = “0”; output; end; run;
Other, HI and LOW Dept_Num =put(EMPID, Department_Number.); Dept_Name =put(Dep_num, Department_Name.); Grade_Level =put(EMP_ID, Grade_Level.); Full_Name =put(EMPID, Full_Name.);
Other, HI and LOW Dept_Num =put(EMPID, Department_Number.); Dept_Name =put(Dep_num, Department_Name.); Grade_Level =put(EMP_ID, Grade_Level.); Full_Name =put(EMPID, Full_Name.);
Other, HI and LOW Dept_Num =put(EMPID, Department_Number.); Dept_Name =put(Dep_num, Department_Name.); Grade_Level =put(EMP_ID, Grade_Level.); Full_Name =put(EMPID, Full_Name.);
OPTIONS • FMTSEARCH to search Libraries • NOFMTERR use original values if the format does not exist
Formats Merging Matching Sub Setting New Variables Data Cleaning Reporting Analysis Large Tables Many Tables Many Key Fields Flexibility Efficiency Easy to Use
Thank you Gary McQuown Data and Analytic Solutions Inc. Fairfax, VA. 703-628-5681 http://www.DASconsultants.com SAS is a Registered Trademark of the SAS Institute, Inc. of Cary, North Carolina.