BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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;

 

 

4 REPLIES 4
andreas_lds
Jade | Level 19

Maybe you should start following Maxim 1

This will save you time.

Tom
Super User Tom
Super User

https://en.wikipedia.org/wiki/One_of_These_Things_(Is_Not_Like_the_Others)

 

Spoiler
file &file_extract dsd dlm = ';';
file &file_extract dsd dbms=tab;
file &file_extract dsd dlm='09'x;
Kurt_Bremser
Super User

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;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 849 views
  • 5 likes
  • 4 in conversation