BookmarkSubscribeRSS Feed
uksusu
Calcite | Level 5
I need some help converting a SAS dataset into a specific Text file format
The ideal format for the text files would be:

All files should be in text format with each line of data ended with a {CR}{LF} character pair.
All fields REGARDLESS OF TYPE should be encapsulated in double quotes and separated by a single comma.
Any date values should be in the form “YYYY-MM-DD”.
Header and trailer records are not required.

Below is an example record of the output type I need:

"56979","GCR011","3882","Actual","2010-10-31","179.09"
"45153","GCR011","3000","Actual","2011-01-31","75.80"

Within the dataset dates and numerics are formatted as date and numeric variables.

Thanks in advance
6 REPLIES 6
data_null__
Jade | Level 19
Use a filename where I used TEMP.

[pre]
filename FT56F001 temp;
data _null_;
file FT56F001 dsd termstr=crlf;
set sashelp.class;
today = date();
format today yymmdd10.;
put (_all_)(~);
run;

proc fslist file=ft56f001;
run;
[/pre]
uksusu
Calcite | Level 5
Thanks data _null_.

I got it working apart from one issue. The actual width of my report is much larger than the example and has 45 variables. Before it reached the end of the first observation though the text file creates at carriage return (without a comma separation) and creates a new line.

EG: -
"56979","GCR011","3882","Actual"
"2010-10-31","179.09"
"45153","GCR011","3000","Actual","2011-01-31"
"75.80"

Is there a way around this at all?

Thanks...
uksusu
Calcite | Level 5
Sorry, I've ised the lrecl= to set width and it appears ok.
However, I want to confirm that by setting the lrecl= does that affect the 'carriage return' ({CR}{LF} character pair) I need at the end of each line?

Thanks......
data_null__
Jade | Level 19
You are correct as long as LRECL is big enough for the longest record everthing else will be OK.
uksusu
Calcite | Level 5
Thanks for all the help, it all works perfectly now. 🙂
sss
Fluorite | Level 6 sss
Fluorite | Level 6
Hi

Very simple way to do is by ODS.

Code goes here

ODS CSV FILE="C:\TEXTDATA.CSV";
PROC PRINT DATA=SASHELP.CLASS;
RUN;
ODS CSV CLOSE;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 6 replies
  • 2891 views
  • 0 likes
  • 3 in conversation