BookmarkSubscribeRSS Feed
Rohit12
Obsidian | Level 7

%let acctage_99=4567;

 

%macro new(var);

data new;

set old;

if &var<&var_99 then &var=&var_99;

run;

%mend;

 

%new(Acctage)

 

In the old dataset I am having a variable Acctage which I need to comapre with macro variable(acctage_99) and then assign the value of acctage_99 to variable acctage


how can I acheive this through macro

5 REPLIES 5
pau13rown
Lapis Lazuli | Level 10

you should indicate what error or warning message you're seeing so that people can assist. I think you're missing a period '.' though ie after "&var" as follows: "if &var<&var._99 then &var=&var._99;"

Rohit12
Obsidian | Level 7

actually i am not getting any error .But mu code is not running what i want 

 

if &var<&var_99 then &var=&var_99;

 

below line resolves into 

if acctage<acctage_99 then acctage=acctage_99

 

there comes a note in the log 

 

variable acctage_99 is uninitiliazed which is corect 

 

what I want is  this

if acctage< 4567 then acctage=4567

 

thanks

pau13rown
Lapis Lazuli | Level 10

did you try what i suggested? if it is saying "acctage_99 is uninitiliazed" in the log then what i suggested is likely the problem

Kurt_Bremser
Super User

You set acctage_99, but you never use it. I guess it should have been

if &var. < &&var._99 then &var. = &&var._99;

Even better would be to use the max() function:

&var. = max(&var.,&&var._99);
Astounding
PROC Star

Given that &VAR is ACCTAGE, and given that you want to compare to the macro variable (not the DATA step variable) &ACCTAGE_99, you will need a slightly different expression:

 

if &var < &&&var._99 then &var = &&&var._99;

 

The three pieces within &&&var._99 are:

 

&& ==> &

&var. ==> Acctage

_99 ==> _99

 

So the whole thing resolves properly into &Acctage_99

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 5 replies
  • 1625 views
  • 1 like
  • 4 in conversation