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!
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?
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;
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.
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?
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
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;
filename x "&MYLOCATION/IDS.TXT" termstr=crlf;
- it works.
Thanks,
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.