Data visualization with SAS programming

Different Titles for Different Plots Within a Single Proc GPLOT With a BY Statement

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Different Titles for Different Plots Within a Single Proc GPLOT With a BY Statement

Is it possible to create different titles for different plots within a single proc gplot, e.g. “Historical Admission Activity” for the first two, “SAT Scores by Year” for the next two, and “ACT Scores by Year” for the last two?  If so, how would I do that?  Running the code below gives all the graphs the ACT version of the title.

Because all the graphs for an institution must appear together (before the graphs for the next institution begin), using three separate
proc gplots does not solve the problem. Thanks in advance for any ideas you can suggest. 

proc gplot data=IPEDSData;                     

by inst_name;

options nobyline;

      title 'Historical Freshmen Admission Activity';

      plot  apps*year

            admits*year

            matrics*year/ overlay;

      plot  selectivity*year

            yield*year        / overlay;

      title 'SAT Scores by Year';

      plot  SAT_CR_75*year

            SAT_CR_25*year/ overlay;

      plot  SAT_Math_75*year

            SAT_Math_25*year/ overlay;

      title 'ACT Scores by Year';

      plot  ACT_Eng_75*year

            ACT_Eng_25*year/ overlay;

      plot  ACT_Math_75*year

            ACT_Math_25*year/ overlay;

run;

quit;


Accepted Solutions
Solution
‎05-14-2015 04:21 PM
Super Contributor
Posts: 291

Re: Different Titles for Different Plots Within a Single Proc GPLOT With a BY Statement

statmam, you might just add some macro code, a where statement and the run statements. Something like the following should get you started ...

%macro one;

%do I = 1 %to 5; **number of institutions;

%if &1=1 %then %let inst="Institution1";

%else %if &I = 2 %then %let inst="Institution2";

and so on ...

proc gplot data=IPEDSData; 

      where inst_name="&inst";                   

*by inst_name;

*options nobyline;

      title 'Historical Freshmen Admission Activity';

      plot  apps*year

            admits*year

            matrics*year/ overlay;

      plot  selectivity*year

            yield*year        / overlay;

run;

      title 'SAT Scores by Year';

      plot  SAT_CR_75*year

            SAT_CR_25*year/ overlay;

      plot  SAT_Math_75*year

            SAT_Math_25*year/ overlay;

run;

      title 'ACT Scores by Year';

      plot  ACT_Eng_75*year

            ACT_Eng_25*year/ overlay;

      plot  ACT_Math_75*year

            ACT_Math_25*year/ overlay;

run;

%mend one;

%one;;

quit;

View solution in original post


All Replies
SAS Super FREQ
Posts: 676

Re: Different Titles for Different Plots Within a Single Proc GPLOT With a BY Statement

Hi

As Proc GPLOT supports Run Groups, add a RUN; statement between the various graphs you create. This should give you what you want. See also sample below.

proc gplot data=sashelp.class;
  title 'first title';
 
plot  age * weight age * height / overlay;
run;
 
title 'second title';
 
plot  weight * age weight * height / overlay;
run;
quit;
Occasional Contributor
Posts: 7

Re: Different Titles for Different Plots Within a Single Proc GPLOT With a BY Statement

Thanks, Bruno.  I gave your idea a try.  Unfortunately, the run groups caused the order to change, i.e. the first graph was produced for all institutions, and then the second graph for everyone, and so on - whereas I need to produce all the graphs for the first institution, and then all the graphs for the second institution, etc.  Thanks for the suggestion though.

Solution
‎05-14-2015 04:21 PM
Super Contributor
Posts: 291

Re: Different Titles for Different Plots Within a Single Proc GPLOT With a BY Statement

statmam, you might just add some macro code, a where statement and the run statements. Something like the following should get you started ...

%macro one;

%do I = 1 %to 5; **number of institutions;

%if &1=1 %then %let inst="Institution1";

%else %if &I = 2 %then %let inst="Institution2";

and so on ...

proc gplot data=IPEDSData; 

      where inst_name="&inst";                   

*by inst_name;

*options nobyline;

      title 'Historical Freshmen Admission Activity';

      plot  apps*year

            admits*year

            matrics*year/ overlay;

      plot  selectivity*year

            yield*year        / overlay;

run;

      title 'SAT Scores by Year';

      plot  SAT_CR_75*year

            SAT_CR_25*year/ overlay;

      plot  SAT_Math_75*year

            SAT_Math_25*year/ overlay;

run;

      title 'ACT Scores by Year';

      plot  ACT_Eng_75*year

            ACT_Eng_25*year/ overlay;

      plot  ACT_Math_75*year

            ACT_Math_25*year/ overlay;

run;

%mend one;

%one;;

quit;

Occasional Contributor
Posts: 7

Re: Different Titles for Different Plots Within a Single Proc GPLOT With a BY Statement

Thank you, Bill.  I am working on implementing your suggestion.  There are 3500+ institutions in the data set (although the program usually runs against a smaller subset of them), so an automatic numbering system will be required.  I'm hoping that perhaps the newfile=bygroup option will produce the numbered data sets for the looping step.

Super Contributor
Posts: 291

Re: Different Titles for Different Plots Within a Single Proc GPLOT With a BY Statement

I gave you the manual view. You could create a list of the institutions and read it into the macro code and avoid all of the manual %let statements.

SAS Super FREQ
Posts: 676

Re: Different Titles for Different Plots Within a Single Proc GPLOT With a BY Statement

Have a look at this great blog by https://communities.sas.com/people/Chris%40SAS http://blogs.sas.com/content/sasdummy/2012/03/20/sas-program-by-processing/ it gives a great introduction on how to automate on the principle suggested by Bill

Occasional Contributor
Posts: 7

Re: Different Titles for Different Plots Within a Single Proc GPLOT With a BY Statement

Ah, this is great.  Just what I needed.  Thanks to you both!

SAS Super FREQ
Posts: 676

Re: Different Titles for Different Plots Within a Single Proc GPLOT With a BY Statement

If your happy with the answers, please mark the discussion as answered, this will help others, when they search for similar questions

Bruno

Occasional Contributor
Posts: 7

Re: Different Titles for Different Plots Within a Single Proc GPLOT With a BY Statement

Bruno, I have been trying to do so; however, for some reason those green and yellow buttons don't show for me (even though I am logged in).  One of the administrators is currently trouble-shooting the issue.  As soon as the buttons show up, I will come back to mark the question answered.  Thanks again for your kind assistance.   

SAS Super FREQ
Posts: 676

Re: Different Titles for Different Plots Within a Single Proc GPLOT With a BY Statement

Statmam

Thanks for the information.

Bruno

☑ This topic is SOLVED.

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

Discussion stats
  • 10 replies
  • 736 views
  • 3 likes
  • 3 in conversation