/***************************************************************************************************************** SAS file name: Drop_Common_Suffix.sas File location: _________________________________________________________________________________________________________________ Purpose: To demonstrate how to drop all variables that have a common suffix from a SAS data set. Author: Peter Clemmensen Creation Date: 01/06/2017 This program support the example page "Drop or Keep Variables with Common Sufix in SAS" on SASnrd.com *****************************************************************************************************************/ /* Create Test Data */ data testdata; input ID FirstVar SecondVar ThirdVar One Two Three; datalines; 1 1 2 3 1 2 3 2 4 5 6 4 5 6 3 7 8 9 7 8 9 4 1 2 3 1 2 3 5 4 5 6 4 5 6 ; /* Define common suffix for variables to be dropped */ %let suffix=var; proc sql noprint; select name into :vars separated by ' ' from dictionary.columns where upcase(libname)=upcase('work') and upcase(memname)=upcase('testdata') and upcase(substr(name,length(name)-(length("&suffix")-1),length("&suffix")))=upcase("&suffix"); quit; /* Put the variables to be dropped for control */ %put &vars; /* Create data set without the variables with the common suffix */ data want; set testdata; if length("&vars") ne 0 then do; drop &vars; end; run;