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

I have recently been asked to prepare some data in a txt file. The tricky part about this is that there is not delimiter between columns and text alignment some time has to be different. For example, a data set as below:

year quarter sin_no gender dob income

2012 Q1 123123123 M 19600103 87000

2013 Q1 123123123 M 19600103 103000

2013 Q1 123123156 F 19571020 130000

2014 Q1 123123789 F 19670912 90100

 

The data should be export as

2012Q1123123123M19600103     87000

2013Q1123123123M19600103   103000

2013Q1123123156F19571020    130000

2014Q1123123789F19670912      90100

 

I was doing my research and debating if I should use a data step or proc export to do the job. 

Then, I found that the data step and the put statment should do the magic.

 

filename outtext "~\export_data.txt";

data _NULL_;

     set to_export;

     filename outtext;

     put year @5 quarter @7 sin_no @16 gender @17 dob @25 income 9.-r;

run;

 

The only part that I am not able to figure out is the end of line. I would want to have CRLF even it is on a Unix envionment. Some post suggested using termstr=CRLF in the file statement, but when I check the documentation, the option is only available to the INFILE statement.

 

Any idea?

1 ACCEPTED SOLUTION

Accepted Solutions
cokeyng
Obsidian | Level 7
Tried out the TERMSTR=CRLF option and it works.
data _NULL_;
set to_export;
filename outtext termstr=crlf;
put year @5 quarter @7 sin_no @16 gender @17 dob @25 income 9.-r;
run;

View solution in original post

1 REPLY 1
cokeyng
Obsidian | Level 7
Tried out the TERMSTR=CRLF option and it works.
data _NULL_;
set to_export;
filename outtext termstr=crlf;
put year @5 quarter @7 sin_no @16 gender @17 dob @25 income 9.-r;
run;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 3162 views
  • 1 like
  • 1 in conversation