DATA Step, Macro, Functions and more

Custom delimiter for text output

Accepted Solution Solved
Reply
Contributor
Posts: 66
Accepted Solution

Custom delimiter for text output

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!


Accepted Solutions
Solution
‎09-14-2011 09:22 AM
PROC Star
Posts: 7,468

Custom delimiter for text output

Posted in reply to Danglytics

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


All Replies
Regular Contributor
Regular Contributor
Posts: 166

Custom delimiter for text output

Posted in reply to Danglytics

Hi,

Will Proc export not work for you ?

Frequent Contributor
Posts: 75

Re: Custom delimiter for text output

Posted in reply to Danglytics

You can use PROC EXPORT

PROC EXPORT

     DATA=SASHELP.CLASS

     OUTFILE="pathname.txt"

     DBMS=DLM

     REPLACE;

     DELIMITER='~';

RUN;

Hope this helps....!

Thanks

Dhanasekaran R

Contributor
Posts: 66

Custom delimiter for text output

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.

Solution
‎09-14-2011 09:22 AM
PROC Star
Posts: 7,468

Custom delimiter for text output

Posted in reply to Danglytics

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;

Contributor
Posts: 66

Custom delimiter for text output

Thank you, this worked pefectly.

Respected Advisor
Posts: 3,799

Re: Custom delimiter for text output

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 346 views
  • 1 like
  • 5 in conversation