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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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