Help using Base SAS procedures

Proc Export - format for .txt file

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

Proc Export - format for .txt file


Hi,

I have a SAS data set with one column in character format that looks like this:

ID

239438233

485574323

048573493

495840312

I need to export it to a .txt file, and have it look the same as above when opening the text file.  Unfortunately when I export it and open it in notepad I can't get each ID on its own line.

When I export the file I get:

239438233485574323048573493495840312

The 4 IDs come out as on long string.  Here's the code I'm using:

PROC EXPORT DATA=USER_IDS;

      OUTFILE= "&MYLOCATION/IDS.TXT"

     REPLACE;

     PUTNAMES=NO;

RUN;

Any ideas on modifications I can make to this block of code to get the desired output?

Thank you!


Accepted Solutions
Solution
‎05-21-2015 04:15 PM
Super User
Posts: 10,497

Re: Proc Export - format for .txt file

PROC EXPORT DATA=USER_IDS;

      OUTFILE= "&MYLOCATION/IDS.TXT"

     dbms=dlm

     REPLACE;

     delimiter=' ';

     PUTNAMES=NO;

RUN;

If this isn't generating one per row, then consider are you generating the output with unix and looking at it in Windows or vice versa?

View solution in original post


All Replies
Super User
Posts: 6,936

Re: Proc Export - format for .txt file

You did not specifiy DBMS=, that may be the reason.

In cases like this, I would not use proc export at all;

Try this:

data _null_;

file "&MYLOCATION/IDS.TXT";

set USER_IDS;

put ID;

run;

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 41

Re: Proc Export - format for .txt file

Thanks Kurt!  I tried your code and got the same results, where all the IDs come out in one long string.  Then I used my code and played with the DMBS= statement, but couldn't get the desired output, which is one ID on each line in the .txt file.

Solution
‎05-21-2015 04:15 PM
Super User
Posts: 10,497

Re: Proc Export - format for .txt file

PROC EXPORT DATA=USER_IDS;

      OUTFILE= "&MYLOCATION/IDS.TXT"

     dbms=dlm

     REPLACE;

     delimiter=' ';

     PUTNAMES=NO;

RUN;

If this isn't generating one per row, then consider are you generating the output with unix and looking at it in Windows or vice versa?

Contributor
Posts: 41

Re: Proc Export - format for .txt file

Hi Ballardw,

You nailed it.  That was the problem.  I created the file and put in on the Unix Server.  The format was correct there.  When I moved it to Windows, that's when it became one long string.  To solve the issue, within winscp, I went to Options-->Preferences-->Transfers-->Edit-->

...and under "Transfer Mode" checked the 'Automatic' Box

Super User
Posts: 9,676

Re: Proc Export - format for .txt file

Your END LINE character is not right . Try :

filename x "&MYLOCATION/IDS.TXT"  termstr=lf;

OR

filename x "&MYLOCATION/IDS.TXT"  termstr=crlf;

PROC EXPORT DATA=USER_IDS;

      OUTFILE=x

     REPLACE;

     PUTNAMES=NO;

RUN;

User Liu
User
Posts: 1

Re: Proc Export - format for .txt file

filename x "&MYLOCATION/IDS.TXT"  termstr=crlf;

- it works. 

 

Thanks,

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 3251 views
  • 7 likes
  • 5 in conversation