turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Trouble with arithmetic operators in Macros

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-24-2009 08:35 PM

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?

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?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-24-2009 08:43 PM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Cynthia_sas

05-25-2009 08:08 AM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-25-2009 08:46 AM

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

Scott Barry

SBBWorks, Inc.

http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001962663.htm

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-26-2009 07:53 AM

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

%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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Peter_C

05-26-2009 04:15 PM

Cynthia/Scott/Peter,

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

-MBI

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

-MBI