DATA Step, Macro, Functions and more

Saving multiple data sets into ascii files

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Saving multiple data sets into ascii files

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


Accepted Solutions
Solution
‎12-18-2013 08:32 PM
Super User
Posts: 19,770

Re: Saving multiple data sets into ascii files

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


All Replies
Super User
Posts: 19,770

Re: Saving multiple data sets into ascii files

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.

New Contributor
Posts: 3

Re: Saving multiple data sets into ascii 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

Solution
‎12-18-2013 08:32 PM
Super User
Posts: 19,770

Re: Saving multiple data sets into ascii files

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

New Contributor
Posts: 3

Re: Saving multiple data sets into ascii files

Thank you so much! filevar works beautifully!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 236 views
  • 3 likes
  • 2 in conversation