SAS_learner
SAS_learner

Reputation: 521

Exporting SAS DataSet on to UNIX as a text file....with delimiter '~|~'

I'm trying to export a SAS data set on to UNIX folder as a text file with delimiter as '~|~'.

Here is the code I'm using....
PROC EXPORT DATA=Exp_TXT
         OUTFILE="/fbrms01/dev/projects/tadis003/Export_txt_OF_New.txt"
         DBMS=DLM REPLACE;
     DELIMITER="~|~";
     PUTNAMES=YES;
RUN;

Here is the output I'm getting on UNIX.....Missing part of delimiter in the data but getting whole delimiter in variable names....

Num~|~Name~|~Age
1~A~10
2~B~11
3~C~12

Any idea why I'm getting part of delimiter in the data only????

Thanks, Sam.

Upvotes: 2

Views: 3602

Answers (3)

o.h
o.h

Reputation: 1262

Since you are using unix, why not make use of unix tools to fix this?

You can call the unix command from your sas program with the X statement: http://support.sas.com/documentation/cdl/en/hostunx/61879/HTML/default/viewer.htm#xcomm.htm

after your export, use sed to fix the file

PROC EXPORT DATA=Exp_TXT
         OUTFILE="/fbrms01/dev/projects/tadis003/Export_txt_OF_New.txt"
         DBMS=DLM REPLACE;
     DELIMITER="~";
     PUTNAMES=YES;
RUN;

X sed 's/~/~|~/g' /fbrms01/dev/projects/tadis003/Export_txt_OF_New.txt > /fbrms01/dev/projects/tadis003/Export_txt_OF_New_v2.txt ;

It might take tweaking depending on your unix, but this works on AIX. Some versions of sed can use the -i flag to edit in place so you don't have to type out the filename twice.

It is a much simpler and easier single-line solution than a big macro.

Upvotes: 0

Joe
Joe

Reputation: 63424

The problem is referenced on the SAS manual page for the FILE statement http://support.sas.com/documentation/cdl/en/lestmtsref/63323/HTML/default/viewer.htm#n15o12lpyoe4gfn1y1vcp6xs6966.htm

Restriction:Even though a character string or character variable is accepted, only the first character of the string or variable is used as the output delimiter. The FILE DLM= processing differs from INFILE DELIMITER= processing.

However, there is (as of some version, anyhow) a new statement, DLMSTR. Unfortunately you can't use DLMSTR in PROC EXPORT, but if you can't easily write the variables out, you can generate the log from a PROC EXPORT and paste it into your program and modify DELIMITER to DLMSTR. You could even dynamically do so - use PROC PRINTTO to generate a file with the log, then read in that file, parse out the line numbers and the non-code, change DELIMITER to DLMSTR, and %include the code.

Upvotes: 0

BellevueBob
BellevueBob

Reputation: 9618

My guess is that PROC EXPORT does not support using multiple character delimiters. Normally, column delimiters are just a single character. So, you will probably need to write your own code to do this.

PROC EXPORT for delimited files generates plain old SAS code that is then executed. You should see the code in the SAS log, from where you can grab it and alter it as needed.

Please see my answer to this other question for a SAS macro that might help you. You cannot use it exactly as written, but it should help you create a version that meets your needs.

Upvotes: 0

Related Questions