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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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