Hello,
This is a follow on to a previous question I had (https://communities.sas.com/t5/SAS-Programming/Loop-through-observations-and-extract-contents/m-p/62...). I appreciate all the help thus far. I am almost to where I need to be.
I would like to increment through dates within the macro statements below. Instead of: source=NSDQsh201101.zip, I would like to write something like: source=MSDQsh&year&month. And instead of outds=nasdaq.NSDQsh201101 at the bottom, I would like write outds=nasdaq.NSDQsh&year&month.
And then have something like:
%do year=2010 to 2020
%do month=01 to 12
How could i do this? Would I need to wrap all of the statements below under a macro that does the date incrementing?
%zipMemList(source=NSDQsh201101.zip, outds=memlist);
/* execute macro %ReadMemInZip() once per member in zip file */
data _null_;
set memlist;
cmd=cats('%ReadMemInZip(source=',zip,', member=',memname,', outds=want)');
call execute(cmd);
run;
/*Aggregate transaction level data to daily*/
%convertdaily(source=want, outds=nasdaq.NSDQsh201101);
Please show us a representative portion of MEMLIST.
Why are you asking about looping in macro code when you are running data step code?
Either way looping over DATE values instead of separate YEAR/MONTH values will be much easier, especially if you want to go across year boundaries, from September to March for example.
For example here is a data step that generates one call per month from september 2019 to march 2020.
data _null_;
start='01SEP2019'd ;
end='01MAR2020'd;
do offset = 0 to intck('month',start,end);
date=intnx('month',start,offset);
length memname $32 cmd $200;
memname = cats('NSDQsh',put(date,yymmn6.));
source = cats('MSDQsh',put(date,yymmn6.));
cmd=cats('%nrstr(%ReadMemInZip)(source=',source,',outds=nasdaq.',member,')');
call execute(cmd);
end;
run;
The "dates" are actually just file names organized by date (year/month), not true dates. So I am trying to process "NSDQsh201101.zip" through the statements in the post and the final output will be "nasdaq.NSDQsh201101".
Then I want to do the same process to "NSDQsh201102.zip" and output nasdaq.NSDQ201102
Then I want to do the same process to "NSDQsh201103.zip" and output nasdaq.NSDQ201103
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.