Posts

Showing posts with the label SAS sample programs

SAS sample programs

Reading/Writing Files Making a fixed format file Making a SAS Cport file Reading a SAS Cport file Reading multiple raw data files, Version 8 Reading multiple raw data files (version 6.x) Using a SAS macro to "set" multiple files Other Imputing the median Checking for duplicate Ids Macro to compute a rolling standard deviation Changing the length of a character variable Replacing strings Concatenating string variables using CAT functions Simple macro to do repeated procs Eliminate useless variables Matching husbands and wives Creating a wide table from a long dataset using PROC TABULATE How can I "fill down" a variable? Creating a long list of variable names based on an abbreviated one Filling in Missing Values Over Time Dummy Coding a Categorical Variable Using a Macro Program A few SAS macro programs for renaming variables dynamically source: http://oregonstate.edu/dept/statistics/sasclass/examples.htm Creating SAS datasets Read a SAS da...

Short Code Samples

1) IF-THEN-ELSE vs SELECT: The SELECT Loop Multiple IF statements in a DATA Step can be replaced with the more efficient SELECT Loop. If you would normally write: if region=' South ' then quarter=4; else if region=' North ' then quarter=3; else if region=' East ' then quarter=2; else quarter=1; You can accomplish the same thing with the SELECT Loop in a DATA Step: select (region); when (' South ') quarter=4; when (' North ') quarter=3; when (' East ') quarter=2; otherwise quarter=1; end ; source: www.usc.edu 2) IFC and IFN functions:new IF functions: IFN(condition, true-numeric-value, false-numeric-value, missing-numeric-value):IFN returns a numeric value. It returns the true, false or missing value depending on whether the condition is true, false or missing. IFC(condition, true-character-value, false-character-value, missing-character-value):IFC returns a character value. It returns the true, fals...