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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 4 replies
  • 662 views
  • 5 likes
  • 4 in conversation