DATA Step, Macro, Functions and more

macro problem

Posts: 47

macro problem

%let acctage_99=4567;


%macro new(var);

data new;

set old;

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






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

Posts: 29

Re: macro problem

[ Edited ]

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

Posts: 47

Re: macro problem

Posted in reply to PaulBrownPhD

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



Posts: 29

Re: macro problem

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

Super User
Posts: 9,611

Re: macro 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);
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 6,543

Re: macro problem

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

Ask a Question
Discussion stats
  • 5 replies
  • 1 like
  • 4 in conversation