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

 

I was able to use the code belwo to batch process files with names like 201501.csv, 201502.csv,.. etc

 

Now I have 12 files, whose names are named by months, like xxxx-Jan2014.csv, xxxx-Feb2014.csv, ... xxxx-Dec2014.csv.

Is there a way to use the similar code below?

 

%macro run_me;
%let n=1;

%do %while (&n <= 9);
%let filein = xxxx20150&n..csv;

data output&n;
infile &filein;
<data step-->
run;

%let n=%eval(&n+1);
%end;
%mend;
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Yes, but you have to process over a list of values, rather than a range of numbers.  You might call the macro like this:

 

%run_me (month_list=Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)

 

Here's an article that tells you how to do it:

 

http://blogs.sas.com/content/publishing/2015/01/30/sas-authors-tip-getting-the-macro-language-to-per...

View solution in original post

4 REPLIES 4
Astounding
PROC Star

Yes, but you have to process over a list of values, rather than a range of numbers.  You might call the macro like this:

 

%run_me (month_list=Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)

 

Here's an article that tells you how to do it:

 

http://blogs.sas.com/content/publishing/2015/01/30/sas-authors-tip-getting-the-macro-language-to-per...

ballardw
Super User

Or you could step over months numerically and generate the part of the file name:

%let monnum=1;
%let year=2014;
%let name = %sysfunc(putn(%sysfunc(mdy(&monnum,1,&year)),MONYY7.));
%put &name;

If you have a do loop on MONNUM (or use &i where I used &monnum) you create the name part for a series.

 

fengyuwuzu
Pyrite | Level 9
Thank you, ballardw. I will give it a try later.

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
  • 4 replies
  • 819 views
  • 0 likes
  • 3 in conversation