BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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
Meteorite | Level 14

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
Meteorite | Level 14

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 869 views
  • 0 likes
  • 3 in conversation