BookmarkSubscribeRSS Feed
AdamMadison
Fluorite | Level 6

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 bottomI 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);

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Please show us a representative portion of MEMLIST.

--
Paige Miller
Tom
Super User Tom
Super User

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;

 

 

AdamMadison
Fluorite | Level 6

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

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