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

Hi,

 

I have 100 large datasets (a,b,c,d,e...) and 50 variables that I need to exclude from those datasets in a set statement.

 

How can I set up a Macro to efficiently exclude these from each dataset before creating the final dataset 'want'?

 

variables to exclude:

d1, d2, d3, f1, f4, g7, h9...etc

 

data want;

set

a

b

c

d

e

...

run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

No macro needed

 

data want;
    set a b c d e ... ;
    drop d1 d2 d3 f1 f4 ...;
run;

or if you really want to improve the efficiency of the execution time (Again no macro needed but a macro variable ... which is not a macro ... is used)

 

%let excl = (drop=d1 d3 d3 f1 f4 ...);
data want;
    set a&excl b&excl c&excl ...
run;
    

 

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

No macro needed

 

data want;
    set a b c d e ... ;
    drop d1 d2 d3 f1 f4 ...;
run;

or if you really want to improve the efficiency of the execution time (Again no macro needed but a macro variable ... which is not a macro ... is used)

 

%let excl = (drop=d1 d3 d3 f1 f4 ...);
data want;
    set a&excl b&excl c&excl ...
run;
    

 

--
Paige Miller
PetePatel
Quartz | Level 8

Thanks PaigeMiller. The variables need to be dropped within the set statement as they are causing issues when trying to set together. Your second macro code is what I was after.

PaigeMiller
Diamond | Level 26

@PetePatel wrote:

Thanks PaigeMiller. The variables need to be dropped within the set statement as they are causing issues when trying to set together. Your second macro code is what I was after.


Great. But there are no macros here. There is a macro variable, which is not a macro.

--
Paige Miller
ballardw
Super User

@PetePatel wrote:

Thanks PaigeMiller. The variables need to be dropped within the set statement as they are causing issues when trying to set together. Your second macro code is what I was after.


If the particular issue(s) were mismatched variable types or lengths of character variables it may be time to address how the data sets are created.

 

If the issue was just data set size that's another story.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1016 views
  • 1 like
  • 3 in conversation