Help using Base SAS procedures

Creating a comma delimited text file

Reply
Occasional Contributor
Posts: 11

Creating a comma delimited text file

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
Respected Advisor
Posts: 3,777

Re: Creating a comma delimited text file

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]
Occasional Contributor
Posts: 11

Re: Creating a comma delimited text file

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...
Occasional Contributor
Posts: 11

Re: Creating a comma delimited text file

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......
Respected Advisor
Posts: 3,777

Re: Creating a comma delimited text file

You are correct as long as LRECL is big enough for the longest record everthing else will be OK.
Occasional Contributor
Posts: 11

Re: Creating a comma delimited text file

Thanks for all the help, it all works perfectly now. :-)
Contributor sss
Contributor
Posts: 65

Re: Creating a comma delimited text file

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;
Ask a Question
Discussion stats
  • 6 replies
  • 191 views
  • 0 likes
  • 3 in conversation