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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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