DATA Step, Macro, Functions and more

batch process data files with monthly contionout file names (like xxxx-Jan2014.csv, xxxx-Feb2014.csv

Accepted Solution Solved
Reply
Super Contributor
Posts: 312
Accepted Solution

batch process data files with monthly contionout file names (like xxxx-Jan2014.csv, xxxx-Feb2014.csv

 

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;

Accepted Solutions
Solution
‎01-21-2016 01:37 PM
Super User
Posts: 5,081

Re: batch process data files with monthly contionout file names (like xxxx-Jan2014.csv, xxxx-Feb2014

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


All Replies
Solution
‎01-21-2016 01:37 PM
Super User
Posts: 5,081

Re: batch process data files with monthly contionout file names (like xxxx-Jan2014.csv, xxxx-Feb2014

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...

Super Contributor
Posts: 312

Re: batch process data files with monthly contionout file names (like xxxx-Jan2014.csv, xxxx-Feb2014

This works! Thank you, Astounding!
Super User
Posts: 10,490

Re: batch process data files with monthly contionout file names (like xxxx-Jan2014.csv, xxxx-Feb2014

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.

 

Super Contributor
Posts: 312

Re: batch process data files with monthly contionout file names (like xxxx-Jan2014.csv, xxxx-Feb2014

Thank you, ballardw. I will give it a try later.
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 229 views
  • 0 likes
  • 3 in conversation