BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
cjpink07
Calcite | Level 5

I am working with survey responses from a large needs assessment for different areas. I am looking for a way to create individual graphs that show responses to each health behavior question based on each zip code. There are about 100 zip codes and 20 health behavior questions. 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Once the data is in  a nice form the time should be pretty negligible to create the graphs.

If by "booklet" it means a single document with all the health behaviors within a zip that takes a little added programming but you might be surprised how little. A proper sorted data set made from your graph data can be used as a driver to write syntax to make the documents.

 

I would expect with the proper data set that I would be looking at a couple hours to a long day depending on other possible requirements (such as inserting boilerplate or conditional text between graphs).

Assuming you can get one set graphs made with dummy code like this:

proc sgplot data=whatever;
   where zip=12345; /*as an example to graph just one zip code*/
   by healthbehavior; /* or whatever the variable name might be*/
   <actual plot code goes here>
run;

Then a data set that has the Zip codes can do something like this:

data _null_;
   set zipcodedataset ;
   call execute ('ods rtf file="<path>\graphs'||zip||'.rtf" <other ods options>;');
   call execute ('proc sgplot data=whatever;');
   call execute ('where zip='||zip||';');
   call execute ('by healthbehavior;')
   call execute ('<actual plot code goes here>');
call execute ('run;'); call execute ('ods rtf close;'); run;

or use similar code to PUT similar statements to a SAS program file and then %include it when the data step finishes.

 

IF there are multiple types of graphs within each zip code then write the code to do set. Then in the data _null_ have each graph with its set of call execute statements.

 

It is getting the first zip code done that is the "hard" part. Once that is done it is fiddly bits to do 10, 100 or 1000's of Zipcodes.

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

That's a lot of plots, around 2,000! What are you going to do with them once you have them? Depending on what you plan to do, we might be able to suggest other methods.

 

If you really really really really need 2,000 plots, this isn't hard to program. Use PROC SGPLOT with a BY statement.

--
Paige Miller
cjpink07
Calcite | Level 5

Yea that's what I have been doing and yes my company wants each (I mean every single) graph lol

ballardw
Super User

I would be very tempted to structure the data so that I had data that looked like:

Zipcode  MeasureName  (x variable if needed) Value (the y value).

 

Sort as desired by either measure or zip code. Then your graphing code could use By ZipCode Measurename; or By Measurename Zipcode; to provide all the graphs. Or even do two sets, each with different sort so the group could by like measure or by zip code.

 

 

 

cjpink07
Calcite | Level 5

Hmm this may work as well. Can you elaborate on how you would do this? I am about to play around with this is SAS as well. Thank you!

PaigeMiller
Diamond | Level 26

@cjpink07 wrote:

Yea that's what I have been doing and yes my company wants each (I mean every single) graph lol


What are you going to do with all of these plots once you have them?

--
Paige Miller
cjpink07
Calcite | Level 5

The director wants to prepare a booklet on these specific health behaviors for each zip code to present.  I explained how many graphs and how much time this will take but they did not accept my recommendations so I am following orders

ballardw
Super User

Once the data is in  a nice form the time should be pretty negligible to create the graphs.

If by "booklet" it means a single document with all the health behaviors within a zip that takes a little added programming but you might be surprised how little. A proper sorted data set made from your graph data can be used as a driver to write syntax to make the documents.

 

I would expect with the proper data set that I would be looking at a couple hours to a long day depending on other possible requirements (such as inserting boilerplate or conditional text between graphs).

Assuming you can get one set graphs made with dummy code like this:

proc sgplot data=whatever;
   where zip=12345; /*as an example to graph just one zip code*/
   by healthbehavior; /* or whatever the variable name might be*/
   <actual plot code goes here>
run;

Then a data set that has the Zip codes can do something like this:

data _null_;
   set zipcodedataset ;
   call execute ('ods rtf file="<path>\graphs'||zip||'.rtf" <other ods options>;');
   call execute ('proc sgplot data=whatever;');
   call execute ('where zip='||zip||';');
   call execute ('by healthbehavior;')
   call execute ('<actual plot code goes here>');
call execute ('run;'); call execute ('ods rtf close;'); run;

or use similar code to PUT similar statements to a SAS program file and then %include it when the data step finishes.

 

IF there are multiple types of graphs within each zip code then write the code to do set. Then in the data _null_ have each graph with its set of call execute statements.

 

It is getting the first zip code done that is the "hard" part. Once that is done it is fiddly bits to do 10, 100 or 1000's of Zipcodes.

cjpink07
Calcite | Level 5

Got it! Thank you!

Reeza
Super User

I mean, we did create these reports with SAS so there's a ton of functionality available to automate. There were 132 different reports created. 

So it depends on the amount of effort you want to put in to the report, but it's definitely doable. 

 

Super basic starting ideas:

https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md

 

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 ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 9 replies
  • 431 views
  • 0 likes
  • 4 in conversation