/*----------------------------------------------------------------------------- File: StripDownAllCharVariables.sas Author: John Sabel john.sabel@ofm.wa.gov Washington State Education Research & Data Center Creation date: 7/3/12 Version: 1.01 Purpose Applies the SAS function strip() to all character variables in a dataset, the effect of which is to remove all leading and trailing spaces from all fields. Parameters DsnIn: The two level name of a data set. DsnOut: The name of the outputted data set. Debug: (Optional) Y = Don't delete intermidiate data set. N = Delete intermidiate data set. Default is "N". Revisions: Date Version Author Comments 2014-06-23 1.01 John Sample macro call at commented out section at bottom was wrong (i.e. StripAllCharVariables(...). Corrected macro call. -----------------------------------------------------------------------------*/ %macro StripDownAllCharVariables(DsnIn=, DsnOut=, Debug=N); %put --- Start of %upcase(&sysmacroname) macro; %local NumberOfCharFields; proc sql noprint; CREATE TABLE __DSNIN_TABLE_DEFINITION LIKE &DsnIn. ; quit; proc sql noprint; SELECT Name INTO :CharColumnName1 - :CharColumnName999 FROM Dictionary.Columns WHERE UPCASE(LIBNAME) = 'WORK' AND UPCASE(MEMTYPE) = 'DATA' AND UPCASE(TYPE) = 'CHAR' AND UPCASE(MEMNAME) = '__DSNIN_TABLE_DEFINITION' ; %let NumberOfCharFields = &sqlobs.; quit; data &DsnOut.; set &DsnIn.; %do __I = 1 %to &NumberOfCharFields.; &&CharColumnName&__I = strip(&&CharColumnName&__I); %end; run; %if &Debug. = N %then %do; proc sql; DROP TABLE __DSNIN_TABLE_DEFINITION; quit; %end; %put --- End of %upcase(&sysmacroname) macro; %mend StripDownAllCharVariables; /* data TestData; input @1 NumVar1 2. @3 CharVar1 $char8. @11 CharVar2 $char8. ; datalines; 1 A1 B1 2 A2 B2 3 A3 B3 4 A4 B4 4 A5 B5 5 A5 B5 ; run; %StripDownAllCharVariables(DsnIn=TestData, DsnOut=TestData_Out, Debug=N) */