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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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