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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 910 views
  • 0 likes
  • 2 in conversation