BookmarkSubscribeRSS Feed
podarum
Quartz | Level 8

If my data creates hundreds of gplots after using a BY statement.. How can I limit the number.. say I want to only view the first 20 or 30.. thanks

9 REPLIES 9
Astounding
PROC Star

proc gplot data=whatever (obs=###)

Pick a number that represents enough observations for 20 or 30 plots, and ignore the last plot since it may be incomplete.

If you want a more scientific version, you could run through a DATA step to create a subset of your data:

data subset;

   set whatever;

   by my_by_var;

   if last.my_by_var then n_plots + 1;

   output;

   if n_plots=25 then stop;

run;

Then run PROC GPLOT on the subset.

podarum
Quartz | Level 8

Thanks Astounding..

Cynthia_sas
SAS Super FREQ

Or, since your BY variable is in some kind of order, pick the one that's about 20th and use a WHERE statement:

  

where char_byvar le 'DEPT20';

or

where num_byvar le 54;

  

directly in your GPLOT:

proc gplot data=whatever;

...where statement....;

  *plot statements;

run;

quit;

cynthia

podarum
Quartz | Level 8

Thanks Cynthia, would you know how I can I limit the number of inputs shown on the x-axis (eg. Date..) I have way too many showing ?

ballardw
Super User

I assume that you mean you have x values out of a desired range.

you can add an option to your plot statement (s) like: / haxis= value1 to value2 by increment

ro define an AXIS statement if you need more control and reference it:

/haxis=axis1

This approach of restricting range usually generates a warning message if I remember correctly.

If your x values are dates or times some other bits come in how to specify them.

podarum
Quartz | Level 8

Thanks Ballardw, but I mean more like instead of showing 2000.01 ... 2000.02 ..... 2000.03 and so on, which crams it up.. I want to show only say years or quarters or something like 2000.01... 2000.06   that sort of thing.

MikeZdeb
Rhodochrosite | Level 12

hi ... have you tried just using a format , for example the dates in SASHELP.AIR have year and month but you can plot by year on the x-axis ...

goptions reset=all;

proc gplot data=sashelp.air;

plot air*date;

format date year.;

run;

quit;

ballardw
Super User

Actually my example does limit the number of displayed values as well as the range. The BY incremental value controls how many tick marks are displayed.

for examle haxis = 0 to 100 by 50 would have 3 major tick marks at 0, 50 and 100.

I looks like you may have x as a date value and a format of YYMMp8. You could try a YYQ to show year quarter values or YEAR. as MikeZdeb suggests.

MikeZdeb
Rhodochrosite | Level 12

hi ... if you know something about the values of the BY-variable, you can use a WHERE statement

for example ...

data air;

set sashelp.air;

year = year(date);

run;

goptions reset=all;

proc gplot data=air;

plot air*date;

by year;

where year between 1950 and 1952;

run;

quit;

if you want to limit the output by the number of plots, you could try something like this ...

ods listing close;

proc sql number;

ods output sql_results=temp;

select distinct year from air;

ods output close;

select year into :years  separated by ',' from temp where row le 5;

quit;

ods listing;

* generates 5 plots; 

proc gplot data=air;

plot air*date;

by year;

where year in (&years);

run;

quit;

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!

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
  • 9 replies
  • 812 views
  • 3 likes
  • 5 in conversation