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
- /
- General Programming
- /
- SAS macro behaviour university edition vs SAS 9

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

06-12-2016 12:25 PM

SAS advanced cerification prep guide says (in the context of user defined marco variables) that "Mathematical expressions are not evaluated" but in unversity edition the mathematical expressions **are **calculated. Can anybody confirm the behaviour in SAS 9 (I dont have it and have not used it). Will help from exa, point of view.

Thanks

Accepted Solutions

Solution

06-12-2016
06:06 PM

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

06-12-2016 04:10 PM

No, the mathematical expression is not evaluated by the macro variable, but by your SQL. Remember, macro's are text replacement, so your code becomes the following and SQL evaluates the expression. If you want it treated as text, you need to include the quotation marks, either in the macro variable definition or in the SQL.

```
proc sql;
insert into newtable
set automacro = "A_Name" ,usermacro = 1234 + 456;
quit;
```

All Replies

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

06-12-2016 12:32 PM

Not speaking for University Edition, since I don't know it ...

In SAS, math may or may not be performed, depending on the context. In the context of a simple %LET statement, math is not performed:

%let a = 1 + 3;

The value of &A is not calculated merely copied, so it is 5 characters long. But using &A may cause the math to be performed:

%do i=&a %to &b;

Now the math gets performed, and the starting value for the loop is 4.

It is possible that University Edition acts in the same way, and you need the context to understand whether math is performed.

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

06-12-2016 01:08 PM

I take it that the statement "in unversity edition the mathematical expressions **are** calculated" is your own opinion, based on examples you performed with SAS UE.

Maybe you can post one or two typical examples, so that we can run them in an ordinary SAS 9 session. It would seem very odd to me if the results were different.

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

06-12-2016 01:31 PM

Here is a sample code:

%let auto = "A_Name";

%let userm = 1234 + 456;

proc sql;

create table newtable (automacro char , usermacro num);

quit;

proc sql;

insert into newtable

set automacro = &auto ,usermacro = &userm;

quit;

proc sql;select * from newtable;

quit;

The values for column usermacro is saved as 1690 and not as a char 1234+456. And if I change type of the variable usermacro to char in the create table statement then error in the log says "It is invalid to assign a numeric expression to a character value using the SET clause."

The text also says that all the macro values are stored as character.

Solution

06-12-2016
06:06 PM

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

06-12-2016 04:10 PM

No, the mathematical expression is not evaluated by the macro variable, but by your SQL. Remember, macro's are text replacement, so your code becomes the following and SQL evaluates the expression. If you want it treated as text, you need to include the quotation marks, either in the macro variable definition or in the SQL.

```
proc sql;
insert into newtable
set automacro = "A_Name" ,usermacro = 1234 + 456;
quit;
```

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

06-12-2016 06:53 PM

Actually, SQL shouldn't be evaluating it either, ergo the error regarding numeric expressions.