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

Hello Everyone,

 

I have a macro that I am using to run some PROC SQL code. I am using the macro's input both in creating the output table name and in the SQL's WHERE clause. When I run the macro, I don't put quotes around the input string because that would not work when creating the table name. However, I need the input string to have quotes around it for the WHERE clause.

 

Here is an example of the situation below. I've searched around a bunch for solutions to this and none of them seem to be working. I'm still relatively new to SAS, so I really appreciate anyone's advice on this, or if you have a link to a similar solution that would work.

%macro test_example (subject_name);
PROC SQL;
CREATE TABLE WORK.Report_&subject_name. AS

SELECT *
FROM LIB.TABLE_NAME
WHERE FIELD1 = &subject_name.  /*Tried this.*/
WHERE FIELD1 = CAT("'", &subject_name., "'")  /*Tried this too.*/
WHERE FIELD1 = "'"||&subject_name.||"'"  /*Tried this as well.*/
;
QUIT;
%mend;

%test_example(Item1);

I could just create a second input in the macro, one that has single quotes around the same input string repeated, but I feel like there must be a better, simpler solution than that. I am using SAS Enterprise Guide 7.15.

 

Thank you,

Ben

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

did you try this

 

WHERE FIELD1 = "&subject_name"

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

did you try this

 

WHERE FIELD1 = "&subject_name"
bgatch
Calcite | Level 5

novinosrin
Tourmaline | Level 20

Welcome to the SAS forum and I'm glad issue has been resolved. May i request you to mark the solution and close the thread if you don't mind plz.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 710 views
  • 0 likes
  • 2 in conversation