Calcite | Level 5

Plotting Frequencies by date

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!

5 REPLIES 5
Super User

Re: Plotting Frequencies by date

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

Re: Plotting Frequencies by date

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);
output;
end;
end;
format date monyy.;
run;

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

Re: Plotting Frequencies by date

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

Re: Plotting Frequencies by date

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:
http://support.sas.com/sassamples/graphgallery/PROC_SGPLOT.html
Super User

Re: Plotting Frequencies by date

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;
run;```

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.

Discussion stats
• 5 replies
• 3784 views
• 0 likes
• 3 in conversation