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.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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