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

Hi there,

I have encountered two problems I was hoping to get your help on.

First, I have to perform similar datasteps on 4 datasets, 2008, 2009, 2010 and 2011 so I have set up a macro to save me from making 4 copies. However my counting variable ‘yr’ is placed in the middle of the datasets names that is 2008 is dubbed ‘full_2008_bin’ and 2009 is ‘full_2009_bin’. How can I get the macro to accept that? (without changing the name of the original dataset).

Second, I have to read in 10 variables is it possible to make a list say something like xvar = ( var1, var2….) and then simply reference xvar later on?

My code:

%macro COR;
%do yr = 2008 %to 2011;

      DATA cor_w1_&yr
SET cor.full_&yr_bin (keep var1 var2 … var10);

%END;
%MEND;
%COR;
RUN;

Cheers,
JD

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Try something like this:

%let keeplist = var1 - var10;

%macro COR (keeplist =);
%do yr = 2008 %to 2011;

      DATA cor_w1_&yr
SET cor.full_&yr._bin (keep &keeplist);

RUN;

%END;
%MEND;
%COR(keeplist = &keeplist);

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star

Try something like this:

%let keeplist = var1 - var10;

%macro COR (keeplist =);
%do yr = 2008 %to 2011;

      DATA cor_w1_&yr
SET cor.full_&yr._bin (keep &keeplist);

RUN;

%END;
%MEND;
%COR(keeplist = &keeplist);

uMich
Calcite | Level 5

That did the trick,

cheers bro.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 778 views
  • 0 likes
  • 2 in conversation