BookmarkSubscribeRSS Feed
☑ This topic is solved. 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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 1 reply
  • 2101 views
  • 1 like
  • 1 in conversation