BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jeetendersinghc
Fluorite | Level 6

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 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@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))
--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

@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))
--
Paige Miller
jeetendersinghc
Fluorite | Level 6

Thank's Paige. After using %bquote its working now and thanks a lot for clarifying the difference between %quote and %str.

Regards,

Jeetender

 

Astounding
PROC Star
As others have pointed out, this can be done. But it would be much easier if you just removed the commas:

%let demvar = x y z;

Then you won't need any quoting functions such as %str.
jeetendersinghc
Fluorite | Level 6

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.