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-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
  • 5 replies
  • 909 views
  • 4 likes
  • 5 in conversation