Help using Base SAS procedures

Automated creation of datasets

Accepted Solution Solved
Reply
Regular Contributor
Posts: 179
Accepted Solution

Automated creation of datasets

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

 


Accepted Solutions
Solution
‎01-17-2018 05:46 PM
Super User
Posts: 23,754

Re: Automated creation of datasets

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


All Replies
Respected Advisor
Posts: 3,040

Re: Automated creation of datasets

[ Edited ]

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
PROC Star
Posts: 1,817

Re: Automated creation of datasets

Respected Advisor
Posts: 3,040

Re: Automated creation of datasets

Posted in reply to novinosrin

Ooh, I like it, especially the section entitled

 

Best Practice: Just Don't Do It

--
Paige Miller
Solution
‎01-17-2018 05:46 PM
Super User
Posts: 23,754

Re: Automated creation of datasets

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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