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?
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;
@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.
@Reeza wrote a macro for this exact purpose.
https://communities.sas.com/t5/SAS-Communities-Library/Splitting-a-SAS-data-set/ta-p/517960
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.