BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Q1983
Lapis Lazuli | Level 10

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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.

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
PaigeMiller
Diamond | Level 26

Ooh, I like it, especially the section entitled

 

Best Practice: Just Don't Do It

--
Paige Miller
Reeza
Super User

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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1367 views
  • 3 likes
  • 4 in conversation