BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
IanW
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

1 REPLY 1
ballardw
Super User

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;
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 713 views
  • 0 likes
  • 2 in conversation