DATA Step, Macro, Functions and more

Parmbuff

Reply
Super Contributor
Posts: 647

Parmbuff

For the below code i'm not able to read in the value for COND
the value for cond should resolve to:
AND Customer_Segment in ('HOSPITAL')

2.And also if i dont give this condition then the where condition should take only SG

options mprint mlogic symbolgen;
%macro OUTPUT/parmbuff;

%let SG=%scan(%bquote(&syspbuff),1,%str(%(,%)));
%LET cond=%scan(%bquote(&syspbuff),2,%str(%(,%)));


%put SG = &SG;
%put COND= &COND;

proc sql;
Create table ttt as
select * from access
where Sales_group = &sg &COND ;

quit;
%mend OUTPUT;

%OUTPUT('05', AND Customer_Segment in ('HOSPITAL'));
Super User
Posts: 3,113

Re: Parmbuff

I suggest it would be much easier to use macro parameters instead of PARMBUFF:

%macro OUTPUT(SG=, COND=);

macro call:

%OUTPUT(SG=%str('05'), COND=%str(AND Customer_Segment in ('HOSPITAL')));

Then you don't need to unpack the PARMBUFF inside the macro.
Super User
Posts: 9,687

Re: Parmbuff

It is interesting.


[pre]

%macro OUTPUT/parmbuff;

%let SG=%qscan(&syspbuff,1,%str(,%());
%LET cond=%qsubstr(&syspbuff,
%index(&syspbuff,%str(,))+1,
%length(&syspbuff)- %index(&syspbuff,%str(,))-1);


%put SG = &SG;
%put COND= &COND;


%mend OUTPUT;

%OUTPUT('05', AND Customer_Segment in ('HOSPITAL'));
[/pre]


Ksharp
Super Contributor
Posts: 647

Re: Parmbuff

KSharp, Thanks for the help.But I'm getting the following error:
NOTE: Line generated by the macro variable "SG".
1 '05'
-
22
SYMBOLGEN: Macro variable COND resolves to AND Customer_Segment in ('HOSPITAL')
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been
unquoted for printing.
NOTE: Line generated by the macro variable "SG".
1 '05'
-
200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,
a numeric constant, a datetime constant, a missing value, (, *, +, -, ALL, ANY,
BTRIM, CALCULATED, CASE, INPUT, PUT, SELECT, SOME, SUBSTRING, TRANSLATE, USER.

ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: Line generated by the macro variable "COND".
1 AND Customer_Segment in ('HOSPITAL')
-
22
-
200
MPRINT(OUTPUT): Create table ttt as select * from access where Sales_group = '05' AND
Customer_Segment in ('HOSPITAL');
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant,
a datetime constant, a missing value, (, -, SELECT.

ERROR 200-322: The symbol is not recognized and will be ignored.



I tried the following and it worked:
%let parms=%qsubstr(&syspbuff,2,%length(&syspbuff)-2);

%let sg=%scan(&parms,1,%str(,));
%let cond=%scan(&parms,2,%str(,));
%put parms=&parms.;
%put sg=&sg.;
%put cond=&cond.;
Ask a Question
Discussion stats
  • 3 replies
  • 312 views
  • 0 likes
  • 3 in conversation