Data visualization with SAS programming

Produce multiple Plots base on a Variable

Accepted Solution Solved
Reply
Occasional Contributor jo1
Occasional Contributor
Posts: 14
Accepted Solution

Produce multiple Plots base on a Variable

Hi,

 

I was hoping someone could give me a start. I have a dataset from which I have created a sgpanel plot that is currently:

 

panelby Site Season Year

 

Instead what I want to do is to create a new sgpanel plot for each of the Sites so they will be panelby Season Year.  I want it set up so that which sites and how many are in the data set won't matter ie the program will be able to work this out.

 

So I'm assuming that I need to have something that gets a unique list from the variable Site and then loops over the sgpanel code to produce a plot for each site in the list?  Any suggestion on the easiest way to do this.

 

I'm using SAS Enterprise Guide Version 7.11 HF5

 

Thanks
Jo


Accepted Solutions
Solution
‎05-13-2017 12:57 AM
Grand Advisor
Posts: 17,325

Re: Produce multiple Plots base on a Variable

Write the code for one Site. 

Make it a macro using a WHERE clause and parameter for SITE. 

Use a data step and CALL EXECUTE to execute it for every value. The CALL EXECUTE documentation has an example. 

View solution in original post


All Replies
Solution
‎05-13-2017 12:57 AM
Grand Advisor
Posts: 17,325

Re: Produce multiple Plots base on a Variable

Write the code for one Site. 

Make it a macro using a WHERE clause and parameter for SITE. 

Use a data step and CALL EXECUTE to execute it for every value. The CALL EXECUTE documentation has an example. 

Grand Advisor
Posts: 17,325

Re: Produce multiple Plots base on a Variable

The correct answer should be @Sanjay_SAS not my suggestion of a macro. BY processing is more efficient. 

Occasional Contributor jo1
Occasional Contributor
Posts: 14

Re: Produce multiple Plots base on a Variable

See the message I just posted on why the macro worked better for me in this situation - perhaps not as efficient but the result is more appropriate for what I wantd.
Occasional Contributor jo1
Occasional Contributor
Posts: 14

Re: Produce multiple Plots base on a Variable

The "By Site" option did work (although in the code "by" stayed coloured red as if there was an issue) but probably is not that different a result than the "panelby Site Season Year".  The only difference between these two is that in the results it puts a page break between the set of plots for each site.  Why I was after each site done seperately is that the values are quite different and the sgpanel produces a single range on the y-axis that covered all values for all sites, which made a lot of the variation within site not easily visible. 

 

For me the "Call execute" routine worked better as it produced a entirely new plot for each site and therefore the range on the y-axis is appropriate for each individual site.

 

Thanks heaps for the reponse thou, as I'm sure I'll have need to employ both options in further work and had not come across the by option before.

 

Thanks

SAS Super FREQ
Posts: 1,080

Re: Produce multiple Plots base on a Variable

[ Edited ]

Proc SGPANEL BY Site will also produce a new graph per site.  You should use whichever method works for you best.  You can also use more classifiers on the BY variable.

SAS Super FREQ
Posts: 1,080

Re: Produce multiple Plots base on a Variable

I suggest you only need to use:

 

  proc sgpanel data=foo;

    by Site; 

    panelby Season Year;

    plot statements;

  run;

Grand Advisor
Posts: 17,325

Re: Produce multiple Plots base on a Variable

I  just noticed that the SGPROCEDURES don't have BY listed in their Syntax, rather it's in a generic section above which I didn't realize initially.

 

The STAT/PROCS do list a BY in the documentation. The inconsistency is confusing Smiley Frustrated

 

 

 

Grand Advisor
Posts: 10,210

Re: Produce multiple Plots base on a Variable

Have you tried sorting your data by site and then using:

 

By Site;

Panelby Season Year ;

☑ This topic is SOLVED.

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

Discussion stats
  • 8 replies
  • 182 views
  • 1 like
  • 4 in conversation