BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mlogan
Lapis Lazuli | Level 10

Hi All,

I would appreciate if anyone can tell me the code to draw a histogram from the following qualitative data.

Thanks,

DateOutcome
01-Mar-2014Loss
27-Feb-2015Profit
27-Feb-2014Loss
24-Feb-2014Profit
01-Mar-2015Loss
26-Feb-2015Loss
01-Mar-2015Loss
01-Mar-2015Loss
01-Mar-2015Loss
01-Mar-2015Profit
01-Mar-2014Profit
01-Mar-2014Profit
01-Mar-2014Profit
25-Feb-2014Profit

OUTPUT:

Untitled3.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

Try something like this:

proc sgplot data=pnl;
vbar date / stat=freq
 
groupdisplay=cluster group=Outcome;
run;

Chris

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

View solution in original post

7 REPLIES 7
ChrisHemedinger
Community Manager

Try something like this:

proc sgplot data=pnl;
vbar date / stat=freq
 
groupdisplay=cluster group=Outcome;
run;

Chris

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
mlogan
Lapis Lazuli | Level 10

Thanks Chris, It worked!!!

mlogan
Lapis Lazuli | Level 10

Hi Chris,

Do you know by any chance if there is a way to plot the days in the X axis only. I mean Instead of putting all dates, I want to put the days (Monday to Sunday) only. I am not sure if SAS can extract days from dates.

Thanks,

ChrisHemedinger
Community Manager

Of course SAS can do that -- that's the power of SAS formats!

proc sgplot data=pnl;
format Date weekdate10.;
vbar date / stat=freq
 
groupdisplay=cluster group=Outcome;
run;

Chris

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
mlogan
Lapis Lazuli | Level 10

Thanks Chris, I just changes my data and uploaded a new pic, can you please tell me what would be the code for creating a run chart on 2 different year?

I much appreciate your help.

ChrisHemedinger
Community Manager

You new drawing looks like a Series plot.  Series plots need two numeric variables: the date for the X axis and then -- in your case -- the frequency/day for the Y axis?  You can use PROC FREQ or PROC SQL to calculate those frequencies, then feed that into a SERIES plot (using PROC SGPLOT and the SERIES statement), grouping it by YEAR.

You can find an index of great samples here:

Graphically Speaking Blog, Visual Index

Chris

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
mlogan
Lapis Lazuli | Level 10

Hi Chris,

Your instruction is working, but I have both year data for the month of February and March only. When I plot them with the following code it leaves a huge gap in the middle (from apr 2014 to jan 2015) of the X axis. Can you please help?

proc template;

  define statgraph tes1;

    begingraph / subpixel=on;

      entrytitle 'test title';

      layout overlay / xaxisopts=(display=(ticks tickvalues))

                       yaxisopts=(griddisplay=on);

  seriesplot x=Start_date y=count / group=Visit_concern name='a' lineattrs=(thickness=1) smoothconnect=true;

  scatterplot x=Start_date y=count / group=Visit_concern markerattrs=(symbol=circlefilled color=white size=1);

        /*scatterplot x=Start_date y=count / group=Visit_concern markercharacter=label; --- this brings the circular data points*/

        discretelegend 'a' / title='Legend' itemsize=(linelength=10px) location=inside across=1 halign=right valign=top;

       endlayout;

    endgraph;

  end;

run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2697 views
  • 6 likes
  • 2 in conversation