Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem of macro var in SQL Execute ( )

Status
Not open for further replies.

6656

Programmer
Nov 5, 2002
104
US
How to solve the problem of using macro varible in Proc SQL / Execute(set ....where .... ) instead of a hardcode value. There is no problem if using a hardcode (='ABC').
If using sigle quote (='&macv'), no update happen and no erro in log; Double quote will cause error (Error Code: -207 Invalid column name 'ABC').

e.g.
%let macv=ABC
proc sql;
connect to sybase(user=username password=sybpass ...... );
execute (update sybase_table
set column1=1
where column6='&macv')
by sybase;
disconnect from sybase;
quit;

Thanks in advance. Merry X'mas!

 
Try setting the macro var with the single quotes.
ex. %let mvar = 'ABC';
then in your SQL execute statement you can now say
where..... = "&mvar";
when the sas macro compiler resolves this macro var it will now be ....='ABC'. and this you say works. I hope this helps.
Have a merry xmas!!!
 
Hi Klaz2002,

The method to set macro value with single quote, then passed it in double quote to Execute (update...) statement and it was till treated as column name.

The solution I used add one more Execute statement to turn off set_identifier option.
e.g. execute (set quoted_identifier off) by sybase;
execute (update............) by sybase;
 
You could also try the following

%NBRQUOTE(argument) which masks from intrepretation during execution all special characters and mnemonic operators, including ampersands and percent signs, in th eresolved value of the argument.

%NRSTR(argument) which masks from intrepretation by the macro processor during macro compilation all special characters and mnemonic operators, including ampersands and percent signs, in the resolved value of the argument.

%SUPERQ(macro-variable) which masks from intrepretation by the macro processor at execution all special characters and mnemonic operators, including ampersands and percent signs, in the value of the macro-variable.

QueryMan

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top