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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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