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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 823 views
  • 1 like
  • 4 in conversation