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
On second thought use the filevar option instead, page 3, second column in first paper. Easy to understand I think
http://www2.sas.com/proceedings/sugi27/p082-27.pdf
or SAS example here:
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.
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
On second thought use the filevar option instead, page 3, second column in first paper. Easy to understand I think
http://www2.sas.com/proceedings/sugi27/p082-27.pdf
or SAS example here:
Thank you so much! filevar works beautifully!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.