BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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