data states;
set states1;
run;
sample output
State id
AK 111
AL 122
CA 131
data AK AL CA;
set states;
if state = 'AK' then output ala;
if state = 'AL' then output AL;
if state = 'CA' then output CA;
etc.....to all 50 states
run;
1. I want to create a dataset for each state and eventually create a separate output tab report for each. If the state pulls no record I want a blank dataset with the states name
2. Is there a way to loop through this without manually creating 50 datasets as shown here
Maybe rather than talk about automatic creation, let's talk about creating an Excel file with a Tab for each group.
https://support.sas.com/rnd/base/ods/odsmarkup/excelxp_demo.html#data
See the example above - run it! And then you can use ODS EXCEL (SAS 9.4+) to create a native Excel file with a sheet for each BY group by default.
If you keep all the data in a single data set, and use the BY statement, you can do all of your analyses by state.
To create different tabs (do you mean Excel tabs?), I think you'd have to do some sort of looping in a macro. Even then, manual creation of datasets, or even a manual creation of the list of states, is not necessary.
This topic is well covered in this post.
http://www.sascommunity.org/wiki/Split_Data_into_Subsets
or here:
https://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/
Courtesy of @Reeza, I got those 2 links from this https://communities.sas.com/t5/SAS-Procedures/A-better-way-to-create-subgroups/m-p/426628#M68366
Ooh, I like it, especially the section entitled
Best Practice: Just Don't Do It
Maybe rather than talk about automatic creation, let's talk about creating an Excel file with a Tab for each group.
https://support.sas.com/rnd/base/ods/odsmarkup/excelxp_demo.html#data
See the example above - run it! And then you can use ODS EXCEL (SAS 9.4+) to create a native Excel file with a sheet for each BY group by default.
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.