BookmarkSubscribeRSS Feed
aowusudommey
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!

 

5 REPLIES 5
Reeza
Super User
PROC FREQ + FORMAT to calculate the percentages by default by dates.
PROC SGPLOT to create the graph.
ballardw
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);
         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;
   
aowusudommey
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.

 

 journal.pone.0184200.g002.PNG

Reeza
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:
http://support.sas.com/sassamples/graphgallery/PROC_SGPLOT.html
ballardw
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;
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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4093 views
  • 0 likes
  • 3 in conversation