DATA Step, Macro, Functions and more

passing string to macro and using bquote

Accepted Solution Solved
Reply
Regular Contributor
Posts: 201
Accepted Solution

passing string to macro and using bquote

[ Edited ]

Can someone please help with this code. It looks OK to me:

 

%macro SomeExcitingMacro(Origin);
	PROC SGPLOT DATA=SASHELP.cars(where=(Origin = %bquote('&Origin.')));
	  VBOX Invoice
	  / category = DriveTrain nooutliers;
	   title &Origin.; 
	RUN;
%mend SomeExcitingMacro;

%SomeExcitingMacro(Asia);

I get this error:

 

ERROR: Syntax error while parsing WHERE clause.

Accepted Solutions
Solution
4 weeks ago
Super User
Posts: 6,527

Re: passing string to macro and using bquote

Posted in reply to csetzkorn

WHERE is fussy about parsing quoted strings  But why use that complication at all?  Why not just:

 

(where=(Origin="&Origin."))

 

There's no apparent reason for %BQUOTE here.

View solution in original post


All Replies
Solution
4 weeks ago
Super User
Posts: 6,527

Re: passing string to macro and using bquote

Posted in reply to csetzkorn

WHERE is fussy about parsing quoted strings  But why use that complication at all?  Why not just:

 

(where=(Origin="&Origin."))

 

There's no apparent reason for %BQUOTE here.

Regular Contributor
Posts: 201

Re: passing string to macro and using bquote

Posted in reply to Astounding
Mmm .. it worked in other scenarios but you are right simpler is better (-:
Super User
Super User
Posts: 9,193

Re: passing string to macro and using bquote

[ Edited ]
Posted in reply to csetzkorn

To resolve a macro reference you need to use double quotes.  But I don;t see why your using bquote at all?

%macro someexcitingmacro (origin);
  proc sgplot data=sashelp.cars;
where origin="&origin."; vbar invoice / category=drivetrain nooutliers;
title "&origin.";
run; %mend someexcitingmacro; %someexcitingmacro(Asia);

You will note I changed some cases and things, nobody likes being shouted at.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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