BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I have the following question

I define the following parameter of dates (YYMM).

 

%let vector=1708+1707+1706+1612;

 

I want to create base on vector parameter another parameter called tarr  that includes also 4 arguments with  + symbol between them.

Each argument is created by subscribing 12 months  and take end of month.

 

The wanted parameter is 

'31AUG2016'd+'31JUL2016'd+'30JUN2016'd+31DEC2015'd

 

 

Can anyone help to do it please?

 

 

 

Thanks

 

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

To what purpose?  Data should go in datasets, datasets and Base SAS are created to manipulate and use data, hence why they have the various formats and functions.  Macro is not for processing data it is a text find an replace system.  Your wanted is just a more complicated way of refering to the numbers already there.

Now you can do it of course, but it really isn't good practice as your just patching bad code:

%let vector=1707+1708+1706+1608;

data _null_;
  length tmp $2000;
  do i=1 to countw("&vector.");
    tmp=catx('+',tmp,cats("'",put(input(scan("&vector.",i,"+"),best.),date9.),"'d"));
  end;
  call symputx('want',tmp);
run;

%put &want.;

However there is nothing redeeming about coding like that whatsoever.

Ronein
Onyx | Level 15

Hello

Thanks for your reply.

The code is running well but the output dates are not as we want.

%let vector=1707+1708+1706+1608;

The required  output is 

%let tarr='31Aug2016'd+'31Jul2016'd+'30Jun2016'd+'31Dec2015'd;

(It is calculated by minus 12 months and taking end of month )

 

 

thanks

Ronein

Ronein
Onyx | Level 15

Hello

I have the following question

I define the following parameter of dates (YYMM).

 

%let vector=1708+1707+1706+1612;

 

I want to create base on vector parameter another parameter called tarr  that includes also 4 arguments with  + symbol between them.

Each argument is created by subscribing 12 months  and take end of month.

 

The wanted parameter is 

'31AUG2016'd+'31JUL2016'd+'30JUN2016'd+31DEC2015'd

 

 

Can anyone help to do it please?

I know that in order to find end of month date we can use the function

intnx('month',mon_now_minus12M_date,0,'E')

 

 

 

Thanks

RW9
Diamond | Level 26 RW9
Diamond | Level 26

"

I know that in order to find end of month date we can use the function

intnx('month',mon_now_minus12M_date,0,'E')

"

Even more reason to use Base SAS then, you have the given formula, use that in code, still don't see what a parameter list fits in?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Ah, ok, then use the intnx function like this:

%let vector=1707+1708+1706+1608;

data test /*_null_*/;
  length tmp $2000;
  do i=1 to countw("&vector.");
    pdate=intnx('month',input(cats(scan("&vector.",i,"+"),"01"),yymmdd8.),-12,"e");
    tmp=catx('+',tmp,cats("'",put(pdate,date9.),"'d"));
  end;
  call symputx('want',tmp);
run;

%put &want.;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2010 views
  • 0 likes
  • 3 in conversation