BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

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;

1 REPLY 1
s_lassen
Meteorite | Level 14

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);

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 856 views
  • 0 likes
  • 2 in conversation