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

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 593 views
  • 1 like
  • 4 in conversation