Hello,
I am trying to create a drop statment using a list of variables in a file eg
"a b c" to drop from a table with EG: "a b c d e f" output should only have var "d e f". Any help is appreciated.
//DRPFLE DD DISP=SHR,DSN=SAS.OUTPUT.DROPLIST
//TBLFLE DD DISP=SHR,DSN=SAS.OUTPUT.TABLE
DATA DRPVAR(KEEP=VARNAME);
INFILE THEFILE END=EOF MISSOVER ;
INPUT @1 VARNAME $CHAR8.
;
DATA DRPSTF (KEEP=VARLIST);
FORMAT VARLIST $32767.;
SET DRPVAR END=EOF;
VARLIST=CATS(' ',VARLIST,VARNAME);
DATA DRPIT;
SET STUFF DRPSTF (DROP=&VARLIST);
PROC PRINT;
If your data set DRPVAR contains names of variables to drop (not stated anywhere) easiest might be a macro variable made this way:
Proc sql noprint; select name into :varlist separated by ' ' from DRPVAR ; quit;
Then use
DATA DRPIT; SET STUFF DRPSTF (DROP=&VARLIST); run;
If your data set DRPVAR contains names of variables to drop (not stated anywhere) easiest might be a macro variable made this way:
Proc sql noprint; select name into :varlist separated by ' ' from DRPVAR ; quit;
Then use
DATA DRPIT; SET STUFF DRPSTF (DROP=&VARLIST); run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.