i have a below table
Data Have;
Input id name $ city $;
cards;
100 Thomas Paris
101 Chris London
102 Martin US
103 John Hongkong
;
run;
for above table i want each city's own table including its records
like a different table named paris which includes only paris data
data have; input id name $ city $; cards; 100 Thomas Paris 101 Chris London 102 Martin US 103 John Hongkong ; run; proc sort data=have out=loop nodupkey; by city; run; data _null_; set loop; call execute(cat('data ',tranwrd(strip(city)," ","_"),'; set have; where city="',strip(city),'"; run;')); run;
The usual question: What for?
In most cases, splitting a dataset is not necessary, as you can use by-group processing to perform analysis for each group (in your case "city") separately in one step.
Splitting more than doubles the required disk space and adds additional steps to be performed, resulting in less efficient code.
AS said above, use by group processing, for example:
proc print data=have; by city; run;
Its far more efficient, in processing, coding, and storage needs.
Thats an example, by group works in all scenarios. If you can be more specific then can show.
data have; input id name $ city $; cards; 100 Thomas Paris 101 Chris London 102 Martin US 103 John Hongkong ; run; proc sort data=have out=loop nodupkey; by city; run; data _null_; set loop; call execute(cat('data ',tranwrd(strip(city)," ","_"),'; set have; where city="',strip(city),'"; run;')); run;
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.