BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

Let's say that I want to split data set sashelp.cars into multiple datasets by the value of field "Length".

I expect to get 67 data sets because there are 67 distinct values of field "Length".

for example:

Name of data set for rows with Length=143 should be tbl_143

Name of data set for rows with Length=169 should be tbl_169

 

What is the clever way to do it please?

 

 

 

3 REPLIES 3
gamotte
Rhodochrosite | Level 12

Hello,

 

I would say that the clever way to do it is not to do it and rather use by group processing.

 

proc sql;
    CREATE TABLE cars AS
    SELECT DISTINCT length
    FROM sashelp.cars;
quit;

data _NULL_;
    set cars;
    call execute(cats('data tbl_',length,'; set sashelp.cars; where length=',length,'; run;'));
run;

 

PaigeMiller
Diamond | Level 26

@gamotte wrote:

Hello,

 

I would say that the clever way to do it is not to do it and rather use by group processing.

Yes, indeed! Not splitting up data sets is the most clever thing to do, because it simplifies your programming and takes advantage of things SAS has already programmed for your benefit.

--
Paige Miller

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