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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.