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!
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;
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.
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.