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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 847 views
  • 3 likes
  • 2 in conversation