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

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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