BookmarkSubscribeRSS Feed

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

5 REPLIES 5
DanielSantos
Barite | Level 11

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

DanielSantos
Barite | Level 11

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

 

set mort_: indsname=tmp;

 

I really miss this feature which is new in 9.2

 

Daniel Santos @ www.cgd.pt

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

DanielSantos
Barite | Level 11

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 🙂

 

Daniel Santos @ www.cgd.pt

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1642 views
  • 0 likes
  • 3 in conversation