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


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!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

6 REPLIES 6
Kurt_Bremser
Super User

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;

teg_76
Calcite | Level 5

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.

ballardw
Super User

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?

teg_76
Calcite | Level 5

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

Ksharp
Super User

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;

Liu
Calcite | Level 5 Liu
Calcite | Level 5

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

- it works. 

 

Thanks,

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 16008 views
  • 7 likes
  • 5 in conversation