DATA Step, Macro, Functions and more

SAS Data Set to Flat Text File

Reply
N/A
Posts: 0

SAS Data Set to Flat Text File

Hi!

Is there any way that I can convert a SAS data set to a flat text file (with no delimiters)?

Thank you.
SAS Super FREQ
Posts: 8,868

Re: SAS Data Set to Flat Text File

Posted in reply to deleted_user
Yes, there is. Depending on your expertise with SAS, you can export the data using the Export Wizard and select a space ( ) character as the delimiter or you can write a DATA _NULL_ program and use PUT statements to create your flat file. There are many examples in the documentation of creating flat files using SAS.

cynthia
Super User
Posts: 10,044

Re: SAS Data Set to Flat Text File

Posted in reply to deleted_user
It looks like Patrick give a solution in the preceding posts.
Such as :
[pre]
data _null_;
set sashelp.class;
file 'd:\download\class.txt';
put name= +1 / sex= +1 / age= +1 /;
run;
[/pre]

It is what you want.
Super User
Posts: 10,044

Re: SAS Data Set to Flat Text File

Posted in reply to deleted_user
Hi!
You can search what you are looking for in sas forum.
Respected Advisor
Posts: 4,173

Re: SAS Data Set to Flat Text File

Posted in reply to deleted_user
Hi
A data step version writing the values of all variable of a data set to an external file without delimiters.
HTH
Patrick

data test;
format b z5.;
a=' abc ';
b=1;
c=' Just a test';
d=1234456778;
e=' The end';
run;

proc sql noprint;
select strip(name) into Smiley TongueutVarList separated by ' +(-1) '
from dictionary.columns
where libname='WORK' and memname='TEST'
;
quit;

%put PutVarList= &PutVarList;

data _null_;
set test;
file print;
put &PutVarList;
run;
Respected Advisor
Posts: 3,799

Re: SAS Data Set to Flat Text File

Seems to me that creating a file with no delimiter, space or otherwise, can only be useful if the length of each field is fixed. You cannot use LIST PUT for that you
would need to use column or formatted put. For example.

[pre]
put a z5. b f8. c$20. d f12. e $16.;
[/pre]

Patrick,

You can make your program much shorter if you take avantage of features of the PUT statement.

[pre]
data _null_;
set test;
file print;
put (_all_) (+(-1));
run;
[/pre]
Ask a Question
Discussion stats
  • 5 replies
  • 248 views
  • 0 likes
  • 5 in conversation