SAS macro behaviour university edition vs SAS 9

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

SAS macro behaviour university edition vs SAS 9

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
Super User
Posts: 17,819

Re: SAS macro behaviour university edition vs SAS 9

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;

 

 

View solution in original post


All Replies
Super User
Posts: 5,081

Re: SAS macro behaviour university edition vs SAS 9

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.

Trusted Advisor
Posts: 1,115

Re: SAS macro behaviour university edition vs SAS 9

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.

New Contributor
Posts: 2

Re: SAS macro behaviour university edition vs SAS 9

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
Super User
Posts: 17,819

Re: SAS macro behaviour university edition vs SAS 9

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;

 

 

Super User
Posts: 17,819

Re: SAS macro behaviour university edition vs SAS 9

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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