DATA Step, Macro, Functions and more

Define the following parameter of dates (YYMM)

Reply
Frequent Contributor
Posts: 97

Define the following parameter of dates (YYMM)

[ Edited ]

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

 

Super User
Super User
Posts: 9,397

Re: Hello I have the following question I define the following parameter of dates (YYMM). %let vec

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.

Frequent Contributor
Posts: 97

Re: Hello I have the following question I define the following parameter of dates (YYMM). %let vec

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

Frequent Contributor
Posts: 97

Create parameter from another parameter

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

Super User
Super User
Posts: 9,397

Re: Create parameter from another parameter

"

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?

Super User
Super User
Posts: 9,397

Re: Create parameter from another parameter

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.;
Super User
Posts: 9,868

Re: Hello I have the following question I define the following parameter of dates (YYMM). %let vec

I merged the two identical questions.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 6 replies
  • 131 views
  • 0 likes
  • 3 in conversation