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
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
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.
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
But then your likely bashing code into stone with with a chisel
Seriously, no reason to hang back on later versions, only big player is 32bit versus 64bit which is a debacle.
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
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.