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?
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 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.
Ready to level-up your skills? Choose your own adventure.