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

Hi all,

I use the following code to separate a large data file into multiple smaller ones. For example, breaking down by the variable rep.

libname saswork 'C:\Documents and Settings\comp$uss\Desktop\SAS';

data test;

input x y z group rep;

datalines;

1 2 3 1 1

2 2 4 1 1

1 1 3 2 1

2 2 8 3 2

3 3 2 4 2

3 4 5 4 2

3 5 6 5 3

2 1 1 5 3

2 3 4 5 4

;

proc sort data=test out=saswork.test;

by rep; run;

%Macro Split;

proc sql noprint;

select distinct rep into :w1 through :w9999 from test;

%let nw = &sqlobs;

data

%do i=1 %to &nw;

saswork.out&&w&i

%end;

;

set test;

select (rep);

%do i=1 %to &nw;

when (&&w&i) output saswork.out&&w&i;

%end;

end;


Using this code, I can get multiple dataset: out1 out2 .... But, what I really want to do is to save these files as ascii files. In other words, I want to create out1.txt out2.txt ... simultaneously. I have tried a few ways, but so far to no avail.


Can anyone help me with this?


Thanks!


SQ

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

On second thought use the filevar option instead, page 3, second column in first paper. Easy to understand I think Smiley Happy

http://www2.sas.com/proceedings/sugi27/p082-27.pdf

or SAS example here:

24599 - Create multiple files from one data set

View solution in original post

4 REPLIES 4
Reeza
Super User

http://www.sascommunity.org/wiki/Split_Data_into_Subsets

I believe there's a variation on the hash solution to extend it to CSV/TXT Files.

sqliu
Calcite | Level 5

Reeza, I appreciate your help.

The code you referred to me is beyond me... Is it possible achieve my goal by modifying the code I provided?

Thanks!

SQ

Reeza
Super User

On second thought use the filevar option instead, page 3, second column in first paper. Easy to understand I think Smiley Happy

http://www2.sas.com/proceedings/sugi27/p082-27.pdf

or SAS example here:

24599 - Create multiple files from one data set

sqliu
Calcite | Level 5

Thank you so much! filevar works beautifully!

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
  • 1289 views
  • 3 likes
  • 2 in conversation