BookmarkSubscribeRSS Feed
aj34321
Quartz | Level 8

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";');

 

4 REPLIES 4
SASKiwi
PROC Star

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.

aj34321
Quartz | Level 8
Using the below for exporting.
PROC EXPORT DATA=SQF
OUTFILE="&EXPORT_FILE_NAME."
DBMS=TAB
REPLACE;
RUN;
Tom
Super User Tom
Super User

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;
Patrick
Opal | Level 21

I believe the issue you're facing is due to how you pass your parameter:

Patrick_0-1646651828091.png

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;

Patrick_0-1646652279153.png

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 1818 views
  • 1 like
  • 4 in conversation