BookmarkSubscribeRSS Feed
anitapamu2
Calcite | Level 5

/*************** macro varaiable *********************/

% let refvar = AEENDT ;

/********************* creating new variable =AEENDY  *******************/

data works._RefDate_;

set  _RefDate_;

RFSTDTC =input ( RFSTDTC  ,YYMMDD10.);

if  &refvar.   le RFSTDTC then  AEENDY  =  &refvar. - RFSTDTC + 1;

if  &refvar.  ge RFSTDTC then  AEENDY  =  &refvar. - RFSTDTC ;

run;

The macro varaible  AEENDT  has suffix "DT" DT should  be place by "DY"...  and  create the new variable.. "  In the above code i have hard code the new variable name "AEENDY ".""

2 REPLIES 2
LinusH
Tourmaline | Level 20

Not sure what kind of dynamics you want, but can't you just use &refvar instead of the hard code variable name?

Data never sleeps
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Why do you want to put the variable name in a macro variable at all, I don't see any benefit?  All your doing is complicating the code.   If you really really have to use macro then put the base part of the variable in the macro and then append the additional part:

% let refvar = AEEN ;

/********************* creating new variable =AEENDY  *******************/

data works._RefDate_;

     set  _RefDate_;

     RFSTDTC =input ( RFSTDTC  ,YYMMDD10.);

     if  &refvar.DT   le RFSTDTC then  &refvar.DY  =  &refvar.DT - RFSTDTC + 1;

     if  &refvar.DT  ge RFSTDTC then  &refvar.DY  =  &refvar.DT - RFSTDTC ;

run;

Again though, this oesn't add any value, so why bother?

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 2 replies
  • 682 views
  • 0 likes
  • 3 in conversation