BookmarkSubscribeRSS Feed
MBI
Calcite | Level 5 MBI
Calcite | Level 5
Hi all,

I'm pretty new to macros and I ran into a roadblock on the code below. I don't understand why the first one works but the second one doesn't. Any help would be appreciated!

-MBI


Example 1 - the 'do' loop is executed
%let A = 1;
%let B = 2;
%let P = (&A + &B);
%if &P = 3 %then %do;
proc sql;
UPDATE nxn SET M1=333 WHERE obs=1;
run;
%end;


Example 2 - the 'do' loop is NOT executed
%let A = 1;
%let B = 2;
%let P = (&A / &B);
%if &P = 0.5 %then %do;
proc sql;
UPDATE nxn SET M1=333 WHERE obs=1;
run;
%end;

I'm also having the same problem with the do loop not executing when using the SQRT operator. Everything seems to work fine if I stay away from division and SQRT. Any ideas?
5 REPLIES 5
Cynthia_sas
Diamond | Level 26
Hi:
I suggest you read the Macro doc on how arithmetic needs to be specified in order to be evaluated correctly:
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001072288.htm
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/z6express.htm

cynthia
MBI
Calcite | Level 5 MBI
Calcite | Level 5
Cynthia,

Wow, thanks for the information. That was perfect! Am I correct in assuming that there is no way to do a SQRT? I didn't see it on the list of operators from:
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/z6express.htm#a001072320

Thanks,

MBI
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You have DATA step functions available in macro language when using the %SYSFUNC macro function. Here is a DOC link - also search the SAS support http://support.sas.com/ website for additional technical references on the topic.

Scott Barry
SBBWorks, Inc.


http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001962663.htm
Peter_C
Rhodochrosite | Level 12
you may find %sysEvalF() helpful, for example [pre] %put sqrt = %sysevalF( 64 ** 0.5 ) ;
%put sqrt = %sysevalF( 60 ** 0.5 ) ;[/pre]

These print square roots in the log, like[pre]1 %put sqrt = %sysevalF( 64 ** 0.5 ) ;
sqrt = 8
2 %put sqrt = %sysevalF( 60 ** 0.5 ) ;
sqrt = 7.74596669241483[/pre]

PeterC
MBI
Calcite | Level 5 MBI
Calcite | Level 5
Cynthia/Scott/Peter,

Thanks so much for the help. My macro is now working properly.

-MBI

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1710 views
  • 0 likes
  • 4 in conversation