BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
lchristensen
Obsidian | Level 7

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.

 

options mprint symbolgen linesize=132;
%let Storage_system = 30689;
%let CSV_Data = z:\mainframe\GPSE\SNCR\CF_Reports\CSV\;
%let Report_Type = Cacheinfo;
%let CSV_Detail_Type = &CSV_Data&Report_Type..csv;
%put 'CSV_Detail file is': &CSV_Detail_Type;
run;
 
data _null_;
quoted_type = catx("'",&CSV_Detail_Type,"'");
call symput(Quoted_CSV,quoted_type);
run;
 
filename CSV_In &Quoted_CSV;
The macro variable CSV_Detail_Type resolves correctly, minus quote marks.
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

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.

lchristensen
Obsidian | Level 7

 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. 

lchristensen
Obsidian | Level 7

Thank you. That works too.

I must be losing my mind because I really think I tried this yesterday too. 

Tom
Super User Tom
Super User

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.'

 

 

Ksharp
Super User

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;

Ksharp_0-1698570792049.png

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 2466 views
  • 1 like
  • 4 in conversation