BookmarkSubscribeRSS Feed
Calcite | Level 5

Hi all,

I had a question I was hoping I can get some help with.


I am attempting to create a plot of multiple variables by month using SAS. 
I'm not sure how to create it so that my x-axis is in monyy. and my Y axis is percentage complete (0-100). 

What would be plotted is the percentage of (1)'s for each variable of interest by month, as the data is binary.


Any insight in how to do this would be much appreciated!


Super User
PROC FREQ + FORMAT to calculate the percentages by default by dates.
PROC SGPLOT to create the graph.
Super User

Do you have an actual SAS date value? Use the desired format in any of the summarization procedures such as Proc Freq  with that variable.


Not that for data coded 1/0 the MEAN of the variable for a group is the percentage of 1's.

If not that likely would be the first step.


What TYPE of graph do you want? Bar, scatter, needle, series or what? And by "multiple variables" do mean to place all of them on a single graph or what?


Here is one way to do bar chart:

data example;
   do date= '01JAN2019'd to '31DEC2019'd;
      do record= 1 to rand('integer',1,50);
         value = (rand('uniform') ge .3);
   format date monyy.;

proc sgplot data=example;
   vbar date /response=value stat=mean;
   format value percent4.;
   yaxis values=(0 to 1 by .1);
Calcite | Level 5

I do have a SAS date value that is currently in monyy, and I have already conducted a proc freq on each variable.


Ideally I would have a series graph with multiple variables on one graph. The y-axis would be percentage and the x-axis would be months. Similar to the attached image.



Super User
Add a GROUP = on the SERIES statement to have a line graph. The documentation has many examples.

Find the closest one to what you want and start with that. Each sample has the full code:
Super User

Data, data, data?


Do you have your percentages already or not?



Sgplot will plot multiple variables if they share a common x axis. Dummy code of an example:


Proc Sgplot data=have;
   series x=date y=percent1;
   series x=date y=percent2;
   series x=date y=percent3;

You would want to sort the data by date, use nice labels for your percentage variables, use the Yaxis statement to set the label and other appearance items and possibly get into a KEYLEGEND statement to control location of the legend.


Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 3 in conversation