BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
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'));
3 REPLIES 3
SASKiwi
PROC Star
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.
Ksharp
Super User
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
SASPhile
Quartz | Level 8
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.;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1752 views
  • 0 likes
  • 3 in conversation