BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RZB
Calcite | Level 5 RZB
Calcite | Level 5

hello

 

i have a dataset for example

 

PROGRAM   DATA

 A                   21780

A                    21781

B                    21782

C                    21782

C                     21783

 

I need to export the data set into multiple txt files with the variable names from the rows  like this:

 

A_21780.txt

A_21781.txt 

B_21782.txt

.

.

.

 

Only the txt file name, and file can be empty.  How i do it?

 

Thank you.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
input PROGRAM  $  DATA;
cards;
 A                   21780
A                    21781
B                    21782
C                    21782
C                     21783
;

data _null_;
 set have;
 filename=cats('c:\temp\',catx('_',program,data),'.txt');
 file dummy filevar=filename;
 put (_all_) (:);
run;

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

I don't understand this. Do you want the TXT files to be empty? If not, what exactly do you want in them?

RZB
Calcite | Level 5 RZB
Calcite | Level 5

Hello,

 

Yes, i only wants the files empty because after splitting them  like user Ksharp says , i posteriorly read them in the path for using it in a step of a SAS program that requires this.

 

thanks.

Kurt_Bremser
Super User

If data is present, the respective output file will not be empty, if no data for a given program/number combination is present, then that file won't be created.

 

 

RZB
Calcite | Level 5 RZB
Calcite | Level 5

many thanks, 

 

Yes , data if present but with

 

put (_all_) (:);     instruction then , the files are exported empty.

Ksharp
Super User
data have;
input PROGRAM  $  DATA;
cards;
 A                   21780
A                    21781
B                    21782
C                    21782
C                     21783
;

data _null_;
 set have;
 filename=cats('c:\temp\',catx('_',program,data),'.txt');
 file dummy filevar=filename;
 put (_all_) (:);
run;
RZB
Calcite | Level 5 RZB
Calcite | Level 5

thank you, that works!

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
  • 6 replies
  • 1255 views
  • 1 like
  • 4 in conversation