BookmarkSubscribeRSS Feed
scb
Obsidian | Level 7 scb
Obsidian | Level 7

May I know how to split dataset into diff dataset based on diff team? I could have 900 teams.  Thanks.

 

DATA have;
INPUT ID $ Team $ Point;
DATALINES;
111 T1 100
112 T1 300
113 T1 600

111 T2 550
112 T2 770
113 T2 890

111 T3 1000
112 T3 3003
113 T3 6003
;
run;

 

Desired result

dataset1 name: T1

ID Team Point

111 T1 100
112 T1 300
113 T1 600

 

dataset2 name: T2

ID Team Point

111 T2 550
112 T2 770
113 T2 890

 

dataset3 name: T3

ID Team Point

111 T3 1000
112 T3 3003
113 T3 6003

 

4 REPLIES 4
novinosrin
Tourmaline | Level 20

DATA have;
INPUT ID $ Team $ Point;
DATALINES;
111 T1 100
112 T1 300
113 T1 600
111 T2 550
112 T2 770
113 T2 890
111 T3 1000
112 T3 3003
113 T3 6003
;
run;

data _null_;
 if _n_=1 then do;
  dcl hash h(dataset:'have(obs=0)',multidata:'y',ordered:'y');
  h.definekey('id');
  h.definedata(all:'y');
  h.definedone();
 end;
 do until(last.team);
  set have;
  by team;
  h.add();
 end;
 h.output(dataset:team);
 h.clear();
run;

Ksharp
Super User

If your table was not sorted and not big.

 

DATA have;
INPUT ID $ Team $ Point;
DATALINES;
111 T1 100
112 T1 300
113 T1 600
111 T2 550
112 T2 770
113 T2 890
111 T3 1000
112 T3 3003
113 T3 6003
;
run;
proc freq data=have noprint;
table team/out=levels nopercent;
run;
data _null_;
 set levels;
 call execute(cat('data ',team,';set have;if team="',strip(team),'";run;'));
run;
Kurt_Bremser
Super User

The most important question here: what for?

In 99% of cases, splitting a dataset makes further processing more complicated and less efficient. So my answer is:

DON'T DO IT!

 

Please provide more details if you think you can persuade me that splitting your dataset makes sense.

Reeza
Super User
I can almost guarantee there's no good reason to do this in SAS...especially 900 times.

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

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
  • 986 views
  • 9 likes
  • 5 in conversation