DATA Step, Macro, Functions and more

Macro Loop

Reply
Frequent Contributor
Posts: 140

Macro Loop

[ Edited ]

Hi,

 

I have 3 years worth of datasets called mort_201401, mort_201402 etc.

 

I need help in creating a loop/macro so that my Data step will pull all the QUARTER END MONTHS ONLY. Does anyone have an idea how I can do this please?

 

Also, I would like another loop/macro to always work out what the last 3 quarter months are and extract that data automatically, is that possible? So if i didn't run for 5 months, it would automatically calculate the quarter month end.

 

Thanks in advance

Super Contributor
Posts: 474

Re: Macro Loop

[ Edited ]

Hi.

 

If you are trying to read from all those table at once, you could gather their names through the dictionary tables (system tables) store the list into a macro var and from there access those from a data step, like this:

 

proc sql noprint;
     select memname into :_TABLES separated by ' ' from dictionary.tables
     where upcase(libname) = 'DATALIB' and index(upcase(memname),'MORT_') eq 1;
quit;


%put tables list: &_TABLES;

 

data want;
     set &_TABLES; * access all tables;

     < do whatever you need to do here >

run;

 

Could you give us an example for part 2 of your question?

 

Hope it helps.

 

Daniel Santos @ www.cgd.pt

Super User
Super User
Posts: 7,392

Re: Macro Loop

As always, no need for macro, use Base SAS which is the programming language.

 

Something like:

data want;
  set mort_: indsname=tmp;
  if substr(indsname,10,2) in ("01","04","07","12") then output;
run;

Update the in () to refelect what the end of quarter is for you, I just assumed 1, 4, 7, 12 months.

Super Contributor
Posts: 474

Re: Macro Loop

Unless you are still running 9.1.3, which is my case... Smiley Sad

 

set mort_: indsname=tmp;

 

I really miss this feature which is new in 9.2

 

Daniel Santos @ www.cgd.pt

Super User
Super User
Posts: 7,392

Re: Macro Loop

But then your likely bashing code into stone with with a chisel Smiley Happy

 

Seriously, no reason to hang back on later versions, only big player is 32bit versus 64bit which is a debacle.

Super Contributor
Posts: 474

Re: Macro Loop

Oh yes.

 

We've got ourselves a weird situation here... Stuck with a 9.1.3 Metadata server because of custom made plugins which aren't supported on later versions... Still the batch server is 9.4

 

Developing like 10 years ago, and running it like today Smiley Happy

 

Daniel Santos @ www.cgd.pt

Ask a Question
Discussion stats
  • 5 replies
  • 145 views
  • 0 likes
  • 3 in conversation