BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Danglytics
Calcite | Level 5

Hi,

I can't seem to figure out how to export text file of my data with the following custom delimiter: |~|

Any help is greatly appreciated, thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Proc export uses the delimiter option (except for variable names) and that only allows one character for a delimiter.  You could always use the brute force method.  That is, run proc export, then press function key4 to retrieve the code that was actually submitted, then modify the code to comment out the dsd and delimiter options and manually put in the delimiter that you want.

For example, the following is the code I just ran for exporting sashelp.class:

   data _null_;

    %let _EFIERR_ = 0; /* set the ERROR detection macro variable */

    %let _EFIREC_ = 0;     /* clear export record count macro variable */

    file 'c:\art\invoice.txt' /*delimiter='|~|' DSD*/ DROPOVER lrecl=32767;

    if _n_ = 1 then        /* write column names or labels */

     do;

       put

          "Name"

       '|~|'

          "Sex"

       '|~|'

          "Age"

       '|~|'

          "Height"

       '|~|'

          "Weight"

       ;

     end;

   set  SASHELP.CLASS   end=EFIEOD;

       format Name $8. ;

       format Sex $1. ;

       format Age best12. ;

       format Height best12. ;

       format Weight best12. ;

     do;

       EFIOUT + 1;

       put Name $        '|~|'@;

       put Sex $ '|~|'@;

       put Age '|~|'@;

       put Height '|~|'@;

       put Weight ;

       ;

     end;

    if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */

    if EFIEOD then call symputx('_EFIREC_',EFIOUT);

    run;

View solution in original post

6 REPLIES 6
NN
Quartz | Level 8 NN
Quartz | Level 8

Hi,

Will Proc export not work for you ?

dhana
Fluorite | Level 6

You can use PROC EXPORT

PROC EXPORT

     DATA=SASHELP.CLASS

     OUTFILE="pathname.txt"

     DBMS=DLM

     REPLACE;

     DELIMITER='~';

RUN;

Hope this helps....!

Thanks

Dhanasekaran R

Danglytics
Calcite | Level 5

I tried proc export but it didnt work, the header has the correct delimiter but the rows after only show the | delimiter instead of |~|

so it looks like the following

col1|~|col2|~|col3|~|

r2c1|r2c2|r2c3|

etc.

art297
Opal | Level 21

Proc export uses the delimiter option (except for variable names) and that only allows one character for a delimiter.  You could always use the brute force method.  That is, run proc export, then press function key4 to retrieve the code that was actually submitted, then modify the code to comment out the dsd and delimiter options and manually put in the delimiter that you want.

For example, the following is the code I just ran for exporting sashelp.class:

   data _null_;

    %let _EFIERR_ = 0; /* set the ERROR detection macro variable */

    %let _EFIREC_ = 0;     /* clear export record count macro variable */

    file 'c:\art\invoice.txt' /*delimiter='|~|' DSD*/ DROPOVER lrecl=32767;

    if _n_ = 1 then        /* write column names or labels */

     do;

       put

          "Name"

       '|~|'

          "Sex"

       '|~|'

          "Age"

       '|~|'

          "Height"

       '|~|'

          "Weight"

       ;

     end;

   set  SASHELP.CLASS   end=EFIEOD;

       format Name $8. ;

       format Sex $1. ;

       format Age best12. ;

       format Height best12. ;

       format Weight best12. ;

     do;

       EFIOUT + 1;

       put Name $        '|~|'@;

       put Sex $ '|~|'@;

       put Age '|~|'@;

       put Height '|~|'@;

       put Weight ;

       ;

     end;

    if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */

    if EFIEOD then call symputx('_EFIREC_',EFIOUT);

    run;

Danglytics
Calcite | Level 5

Thank you, this worked pefectly.

data_null__
Jade | Level 19

This is an option for that.

883  data _null_;

884     set sashelp.class;

885     file log dlmstr='|~|' dsd;

886     put (_all_)(:);

887     run;

Alfred|~|M|~|14|~|69|~|112.5

Alice|~|F|~|13|~|56.5|~|84

Barbara|~|F|~|13|~|65.3|~|98

Carol|~|F|~|14|~|62.8|~|102.5

Henry|~|M|~|14|~|63.5|~|102.5

James|~|M|~|12|~|57.3|~|83

Jane|~|F|~|12|~|59.8|~|84.5

Janet|~|F|~|15|~|62.5|~|112.5

Jeffrey|~|M|~|13|~|62.5|~|84

John|~|M|~|12|~|59|~|99.5

Joyce|~|F|~|11|~|51.3|~|50.5

Judy|~|F|~|14|~|64.3|~|90

Louise|~|F|~|12|~|56.3|~|77

Mary|~|F|~|15|~|66.5|~|112

Philip|~|M|~|16|~|72|~|150

Robert|~|M|~|12|~|64.8|~|128

Ronald|~|M|~|15|~|67|~|133

Thomas|~|M|~|11|~|57.5|~|85

William|~|M|~|15|~|66.5|~|112

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 1572 views
  • 1 like
  • 5 in conversation