BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Son_Of_Krypton
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26
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;

View solution in original post

7 REPLIES 7
Kurt_Bremser
Super User

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.

Son_Of_Krypton
Fluorite | Level 6
asume this question as scenario not as a practical work
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Son_Of_Krypton
Fluorite | Level 6
okay but i don't want to print it i want to create a dataset for each city by its name
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Thats an example, by group works in all scenarios.  If you can be more specific then can show.

Son_Of_Krypton
Fluorite | Level 6
looking for solution if you have any solution in your mind please share
RW9
Diamond | Level 26 RW9
Diamond | Level 26
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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 7 replies
  • 1301 views
  • 3 likes
  • 3 in conversation