BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jo1
Obsidian | Level 7 jo1
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

8 REPLIES 8
Reeza
Super User

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. 

Reeza
Super User

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

jo1
Obsidian | Level 7 jo1
Obsidian | Level 7
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.
jo1
Obsidian | Level 7 jo1
Obsidian | Level 7

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

Jay54
Meteorite | Level 14

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.

Jay54
Meteorite | Level 14

I suggest you only need to use:

 

  proc sgpanel data=foo;

    by Site; 

    panelby Season Year;

    plot statements;

  run;

Reeza
Super User

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 :S

 

 

 

ballardw
Super User

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

 

By Site;

Panelby Season Year ;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 8 replies
  • 894 views
  • 1 like
  • 4 in conversation