Hello
I define a SAS parameter (called vector) that contain for example 2 arguments of dates (YYMM).
I also define another SAS parameter (called tarr) that contain 2 arguments of dates .
tarr parameter contains dates that are 12 months before dates of vector paraemeter (and end of month).
My question is hot to create tarr paremeter automatic from vector parameter??
DATA Tbl1712;
INPUT ID ddate ddmmyy10. Y;
FORMAT ddate ddmmyy10. ;
CARDS;
1 01/01/2018 10
2 01/01/2017 20
3 01/01/2016 30
4 01/01/2015 40
;
Run;
DATA Tbl1612;
INPUT ID ddate ddmmyy10. Y;
FORMAT ddate ddmmyy10. ;
CARDS;
1 01/06/2018 10
2 01/06/2017 20
3 01/06/2016 30
4 01/06/2015 40
;
Run;
%let vector=1712+1612;
%let tarr='31Dec2016'd+'31Dec2015'd;/*My question is how to create it automatically)
%macro Macro1;
%do i=1 %to 2;
%let mon=%scan(&vector.,&i.,+);
%let tar=%scan(&tarr.,&i.,+);
data Output&mon.;
set Tbl&mon.;
if ddate<=&tar. then Y=0;
run;
%end;
%mend;
%Macro1;
You can do it with a function macro, like this:
%macro tarr(vector);
%local date i r plus;
%do i=1 %to %sysfunc(countw(&vector,+));
%let date=%sysfunc(inputn(%scan(&vector,&i,+)01,yymmdd6.));
%let r=&r.&plus.%str(%')%sysfunc(intnx(month,&date,0,e),date9.)%str(%')d;
%let plus=+;
%end;
%unquote(&r)
%mend;
%let tarr=%tarr(&vector);
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.