Help using Base SAS procedures

limit the number of gplots

Reply
Super Contributor
Posts: 401

limit the number of gplots

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

Super User
Posts: 5,511

limit the number of gplots

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.

Super Contributor
Posts: 401

limit the number of gplots

Posted in reply to Astounding

Thanks Astounding..

SAS Super FREQ
Posts: 8,868

limit the number of gplots

Posted in reply to Astounding

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

Super Contributor
Posts: 401

limit the number of gplots

Posted in reply to Cynthia_sas

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 ?

Super User
Posts: 11,343

limit the number of gplots

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.

Super Contributor
Posts: 401

limit the number of gplots

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.

Valued Guide
Posts: 765

Re: limit the number of gplots

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;

Super User
Posts: 11,343

Re: limit the number of gplots

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.

Valued Guide
Posts: 765

Re: limit the number of gplots

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;

Ask a Question
Discussion stats
  • 9 replies
  • 181 views
  • 3 likes
  • 5 in conversation