Hello
I want to export sas data set into TXT file.
I want to use DATA STEP way .
In example 2 I get error
30 file &file_extract dsd dbms=tab;
____
23
ERROR 23-2: Invalid option name DBMS.
What is the way to solve the error?
I also want to add column headers in example2? What is the way to do it?
data junk;
Set sashelp.class;
if sex='F' then age=.;
label
Name='Client_Name'
Sex='Gender'
Age='Age'
Height='Height'
Weight='Weight'
;
run;
/***Example1---Working well****/
%let file_extract='/usr/local/SAS/SASUsers/LabRet/Adhoc/creditCards/Example1.txt';
%put &file_extract;
data _null_;
file &file_extract dsd dlm = ';';
set junk;
put (_all_) (~);
run;
/***Example2---Error****/
%let file_extract='/usr/local/SAS/SASUsers/LabRet/Adhoc/creditCards/Example2.txt';
%put &file_extract;
data _null_;
file &file_extract dsd dbms=tab;
set junk;
put (_all_) (~);
run;
Maybe you should start following Maxim 1
This will save you time.
https://en.wikipedia.org/wiki/One_of_These_Things_(Is_Not_Like_the_Others)
file &file_extract dsd dlm = ';';
file &file_extract dsd dbms=tab;
file &file_extract dsd dlm='09'x;
Maxim 1.
Maxim 1.
Maxim 1.
DBMS= is not a valid option for the FILE Statement.
It is an option available in the IMPORT and EXPORT procedures.
To create a tab-delimited file, use
%let file_extract=/usr/local/SAS/SASUsers/LabRet/Adhoc/creditCards/Example2.txt;
file "&file_extract." dsd dlm="09"x;
To add a header line, create a string with CATX and PUT it at the beginning:
if _n_ = 1
then do;
length header $500; * make it big enough;
header = catx("09"x,"name1","name2","name3"); * add variable names or labels as needed;
put header;
end;
put
name1
name2
name3
; * add variables as needed;
run;
PS you can use PROC EXPORT with DBMS=TAB and then read the log to see how the procedure creates a tab-delimited file with the DATA step.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.