%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
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;"
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
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
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);
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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.