Hi All,
I'm facing issues with the below double quote. I want my dataset to export the below libname as
LIBNAME ABC "&MYPATH./data/temp";
But when it gets exported to a text file it appears as below with extra double quotes marked in red.
"LIBNAME ABC ""&MYPATH./data/temp"";"
How do i get rid of these extra double quotes.
Below is the code that generates this.
DATA SQF; LENGTH SQL_STRING $500; STOP; RUN;
%MACRO INSERT_TEXT(ATEXT);
PROC SQL; INSERT INTO SQF(SQL_STRING) VALUES (&ATEXT.);
%MEND INSERT_TEXT;
%INSERT_TEXT('LIBNAME ABC "&MYPATH./data/temp";');
There's nothing wrong with your program. It produces a SAS dataset with the LIBNAME statement as you wanted it.
How are you exporting it to a text file? It must be your exporting process that is causing the problem.
To create a delimited file that can be parsed any value that contains the delimiter must be enclosed in quotes. That also requires that any quotes also be enclosed in quotes. If you don't want the strings quoted then do not write them to a delimited file.
If you are just writing text to a file why are you using PROC EXPORT?
data _null_;
set SQF;
file "&EXPORT_FILE_NAME.";
put sqf;
run;
I believe the issue you're facing is due to how you pass your parameter:
Because the outer quotes are single quotes macro variable &mypath won't resolve.
Here two options that should you get around this issue.
Option one - outer quotes are double quotes:
%let mypath=/home/user;
DATA SQF;
LENGTH SQL_STRING $500;
STOP;
RUN;
%MACRO INSERT_TEXT(ATEXT);
PROC SQL;
INSERT INTO SQF(SQL_STRING) VALUES (&ATEXT.)
;
quit;
%MEND INSERT_TEXT;
%INSERT_TEXT("LIBNAME ABC '&MYPATH./data/temp';");
Options two - outer quoting within the macro
%let mypath=/home/user;
DATA SQF;
LENGTH SQL_STRING $500;
STOP;
RUN;
%MACRO INSERT_TEXT(ATEXT);
PROC SQL;
INSERT INTO SQF(SQL_STRING) VALUES (%tslit(&ATEXT.))
;
quit;
%MEND INSERT_TEXT;
%INSERT_TEXT(LIBNAME ABC "&MYPATH./data/temp";);
proc print data=sqf;
run;
Using the 2nd option with the %TSLIT() macro has the advantage that you can pass the parameter with single or double quotes. The %TSLIT() macro will then take care to get the rest of the quoting "right".
%MACRO INSERT_TEXT(ATEXT);
PROC SQL;
INSERT INTO SQF(SQL_STRING) VALUES (%tslit(&ATEXT.))
;
quit;
%MEND INSERT_TEXT;
%INSERT_TEXT(LIBNAME ABC "&MYPATH./data/temp";);
%INSERT_TEXT(LIBNAME ABC 'home/user/data/temp';);
proc print data=sqf;
run;
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.