Hi ,
Is there any way i can call macro variable demvar inside the key word macro .
Here is my code and when i am trying to run it I am getting the error :ERROR: More positional parameters found than defined."
%let demvar= x , y, z;
%put &demvar;
%macro table(indata, outdata, varlist );
Proc sql;
create table &outdata. as
select &varlist.
from &indata.
where patid in (select patid from ca)
order by patid;
quit;
%mend;
%table(a, b , (%str(&demvar));My purpose of doing so is to create multiple dataset by changing name of variable of interest in demvar.
Thanks,
Jeetender
@jeetendersinghc wrote:
Hi ,
Is there any way i can call macro variable demvar inside the key word macro .
Here is my code and when i am trying to run it I am getting the error :ERROR: More positional parameters found than defined."%let demvar= x , y, z; %put &demvar; %macro table(indata, outdata, varlist ); Proc sql; create table &outdata. as select &varlist. from &indata. where patid in (select patid from ca) order by patid; quit; %mend; %table(a, b , (%str(&demvar));My purpose of doing so is to create multiple dataset by changing name of variable of interest in demvar.
Thanks,
Jeetender
Try
%table(a,b,%quote(&demvar))
Generally speaking, you want to put the %quote function around a macro variable if it might contain special characters like the comma. In this situation, %str() doesn't help. You would use %str() when you are creating a string and you actually have to type the comma character (or other special character) and not have the comma be treated as having a special meaning like a delimiter, it then gets treated as plain text. Example:
%table(a,b,%str(x,y,z))
@jeetendersinghc wrote:
Hi ,
Is there any way i can call macro variable demvar inside the key word macro .
Here is my code and when i am trying to run it I am getting the error :ERROR: More positional parameters found than defined."%let demvar= x , y, z; %put &demvar; %macro table(indata, outdata, varlist ); Proc sql; create table &outdata. as select &varlist. from &indata. where patid in (select patid from ca) order by patid; quit; %mend; %table(a, b , (%str(&demvar));My purpose of doing so is to create multiple dataset by changing name of variable of interest in demvar.
Thanks,
Jeetender
Try
%table(a,b,%quote(&demvar))
Generally speaking, you want to put the %quote function around a macro variable if it might contain special characters like the comma. In this situation, %str() doesn't help. You would use %str() when you are creating a string and you actually have to type the comma character (or other special character) and not have the comma be treated as having a special meaning like a delimiter, it then gets treated as plain text. Example:
%table(a,b,%str(x,y,z))
Thank's Paige. After using %bquote its working now and thanks a lot for clarifying the difference between %quote and %str.
Regards,
Jeetender
i removed the comma's and still getting the error but this time "
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &, (, *,
**, +, ',', -, '.', /, <, <=, <>, =, >, >=, ?, AND, AS, BETWEEN, CONTAINS, EQ,
EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL, LE, LEN,
LENGTH, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||,
~, ~=.
ERROR 76-322: Syntax error, statement will be ignored.
"
The value which i have mentioned in demvar are the list of variables which i need to keep in my table. so by removing the commas from these values seems wouldn't work.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.