I have %let statements that get combined to give a file location.
I want to use that macro variable as the file location in a filename statement. The problem is I need single quotes around the value of the macro variable.
You don't need to use the function, but double quotes to make a string literal out of the macro variable:
quoted_type = "'&CSV_Detail_Type'";
The outer double quotes prevent the single quotes from masking the macro variable.
You don't need to use the function, but double quotes to make a string literal out of the macro variable:
quoted_type = "'&CSV_Detail_Type'";
The outer double quotes prevent the single quotes from masking the macro variable.
Thank you. I tried lots of combinations and thought I had tried that with the result being it didn't substitute the value of the macro variable and instead had put the macro variable (&CSV_Detail_Type) in quotes.
But tried this and it worked fine.
But you can get all this much easier:
filename CSV_In "&csv_detail_type";
without any intermediate DATA step.
Thank you. That works too.
I must be losing my mind because I really think I tried this yesterday too.
Why do you need single quotes? Is there some other code you are trying to generate than the FILENAME statement?
1 %let CSV_Data = z:\mainframe\GPSE\SNCR\CF_Reports\CSV\; 2 %let Report_Type = Cacheinfo; 3 %let CSV_Detail_Type = &CSV_Data.&Report_Type..csv; 4 %put &=csv_detail_type ; CSV_DETAIL_TYPE=z:\mainframe\GPSE\SNCR\CF_Reports\CSV\Cacheinfo.csv 5 6 filename CSV_In "&csv_detail_type" ; 7 8 %put %sysfunc(pathname(csv_in)); z:\mainframe\GPSE\SNCR\CF_Reports\CSV\Cacheinfo.csv
If do you want to quote a string of unknown value don't just add quotes on either end. Use the QUOTE() function. That will properly double up any quotes that are already in the string.
1 %let mvar=He said "Hello" to me.; 2 %put %sysfunc(quote(&mvar)); "He said ""Hello"" to me." 3 %put %sysfunc(quote(&mvar,%str(%'))); 'He said "Hello" to me.'
Try this one :
%let CSV_Data = z:\mainframe\GPSE\SNCR\CF_Reports\CSV\;
%let Report_Type = Cacheinfo;
%let CSV_Detail_Type = %bquote('&CSV_Data&Report_Type..csv');
%put 'CSV_Detail file is': &CSV_Detail_Type;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.