DATA Step, Macro, Functions and more

create tarr paremeter automatic from vector parameter

Reply
Frequent Contributor
Posts: 142

create tarr paremeter automatic from vector parameter

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;

PROC Star
Posts: 266

Re: create tarr paremeter automatic from vector parameter

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);
Ask a Question
Discussion stats
  • 1 reply
  • 63 views
  • 0 likes
  • 2 in conversation