- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
did you try this
WHERE FIELD1 = "&subject_name"
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello novinosrin, thank you so much!
That resolves correctly and works to pull the data! Appreciate your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.