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.;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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