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-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
  • 4 replies
  • 668 views
  • 1 like
  • 3 in conversation