BookmarkSubscribeRSS Feed
helannivas88
Obsidian | Level 7

Hi,

 

I'm trying to create a .txt file using proc export from sas dataset using pipe delimiter. But in data, there is a pipe value in the field causing us the major problem.

 

Is there a way  can we introduce a escape char or single / doubles quotes in the field where we get the pipe value. Please advise.

 

Thanks

5 REPLIES 5
Reeza
Super User
PROC EXPORT will mask delimiters in the character fields automatically, by adding quotes around it.

A data step export will not. Please show your code & log if you're having issues with PROC EXPORT. Note that PROC EXPORT is not the same as the GUI tasks either, especially in EG and Studio.
ballardw
Super User

@helannivas88 wrote:

Hi,

 

I'm trying to create a .txt file using proc export from sas dataset using pipe delimiter. But in data, there is a pipe value in the field causing us the major problem.

 

Is there a way  can we introduce a escape char or single / doubles quotes in the field where we get the pipe value. Please advise.

 

Thanks


Please describe the "major problem" you are having. Any value that contains a delimiter character that is exported with Proc Export will have the entire string enclosed in quotes.

 

If you run this code (modified to export to a location on your system)

data pipe;
   x='string with| in the middle';
   y='String without';
run;

proc export data=pipe
   outfile="<path>\pipe.txt"
   dbms=dlm replace;
   delimiter='|';
run;

The resulting file will look like:

x|y
"string with| in the middle"|String without

So, we kind of need to know the exact problem you have with using the file.

 

SRAAM
Calcite | Level 5
I used same code and ran it in Linux. I did not see data enclosed in double quotes . Why the default behavior not working in Linux for me
smantha
Lapis Lazuli | Level 10

This code already puts the data in quotes

data _new;
informat have $32.;
input have $ var2;
want=compress(compress(have,' +/*-%','A'));
cards;
BIOL1012|8DCWc	10128
ANT102	102
PSY125	125
SOC101	101
SPAN2330	2330
HIST1500	1500
BCS-205	205
BCS-132	132
;;;
run;

proc export data=_new outfile='test.csv'
dbms=dlm replace ;
delimiter='|' ;
run;
Reeza
Super User
Please don't use CSV extension on files that are not comma or semicolon delimited.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 5 replies
  • 1493 views
  • 4 likes
  • 5 in conversation