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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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