BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Chung-Li
Quartz | Level 8

Hi all,

 

My data contains patients' ID (idd) and charateristic of that patient (TroughHour) as follows:

                                                          Trough
                                          Obs     idd      Hour

                                            1    10002       1
                                            2    10003      23
                                            3    10005       2
                                            4    10006       2
                                            5    10007       4
                                            6    10008       0
                                            7    10009       4
                                            8    10010       3
                                            9    10011       0
                                           10    10012      22
                                           11    10013       4
                                           12    10014       2
                                           13    10015       4
                                           14    10017       2
                                           15    10018       4
                                           16    10023       4
                                           17    10024      22
                                           18    10025       2
                                           19    10026       3
                                           20    10027       0
                                           21    10028      22
                                           22    10029      22
                                           23    10030       3
                                           24    10033       3
                                           25    10034       5
                                           26    10035       3
                                           27    10036      23
                                           28    10037       4
                                           29    10038       1
                                           30    10040      23
                                           31    10041      23
                                           32    10042      23
                                           33    10044       4
                                            .       .        .
                                            .       .        .
                                            .       .        .

 

What I want to do is to draw the frequency or count percentage over the variable "TroughHour".

When we want to draw this, SGPLOT is a very poweful tool, so I use it to do so:

PROC SGPLOT DATA=Have;
	HISTOGRAM TroughHour;
RUN;

The result goes like this:

 

SGPlot1.png

 

Though it does show the percentage, the presentation isn't what I expected exactly.

#1 The range isn't right: I only want to show TroughHour= 22, 23, 0, 1, 2, 3, 4, and 5, but it shows from 0 to 23.

#2 The order isn't correct either: I want it to be presented in the order of 22, 23, 0, 1, 2, 3, 4, 5, but now its order is 0, 1, ..., 23

 

While searching for some useful information by myself, hope you guys can kindly give me a hand.

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

1. This is one of the few cases where Radar Plots are useful, showing different levels over time. 

2. The fastest solution, recode data and use formats to display what you want using a VBAR plot rather than a histogram plot. Though if you recode it probably won't matter which one you use. But since you're binning by the hour it likely doesn't matter anyways. 

3. If you are intersted in looking at your full 24 hour period, I recommend a radar chart. The 24 hour clock works well on that type of graph.

 

proc format;
 value time_fmt
 22 = 1
 23 = 2
 0 = 3
 1 = 4
 2 = 5
 3 = 6
 4 = 7
 5 = 8
 6 = 9
 ;
 
 value $ time2_fmt
 '1' = 22
 '2' = 23
 '3' = 0
'4' = 1
'5' = 2
'6' = 3
'7' = 4
'8' = 5
'9' = 6;
 run;
 
 proc sgplot data=have;
 where hour in (22, 23, 0:5);
 vbar hour2 / stat=freq;
 format hour2 $time2_fmt.;
 run;
 

View solution in original post

5 REPLIES 5
ChrisNZ
Tourmaline | Level 20

Like this?


proc sgplot data=HAVE;
  vbar HOUR;
  xaxis values=(22,23,0,1,2,3,4,5) ;
  format HOUR z2.;
run;

aaa1.PNG

 

ChrisNZ
Tourmaline | Level 20

Oh you want percentages.

If you want no intermediate table (but why not?) , how about this?

 


axis1  order=(22,23,0,1,2,3,4,5) ;
proc gchart;
	vbar HOUR/ maxis=axis1 percent discrete;
  format HOUR z2.;
run;
quit;

aaa1.PNG

 

Chung-Li
Quartz | Level 8

Thanks Chris, 

 

Though I adapt other method, knowing how to put percentage on the bar and change the order are very helpful!

 

Reeza
Super User

1. This is one of the few cases where Radar Plots are useful, showing different levels over time. 

2. The fastest solution, recode data and use formats to display what you want using a VBAR plot rather than a histogram plot. Though if you recode it probably won't matter which one you use. But since you're binning by the hour it likely doesn't matter anyways. 

3. If you are intersted in looking at your full 24 hour period, I recommend a radar chart. The 24 hour clock works well on that type of graph.

 

proc format;
 value time_fmt
 22 = 1
 23 = 2
 0 = 3
 1 = 4
 2 = 5
 3 = 6
 4 = 7
 5 = 8
 6 = 9
 ;
 
 value $ time2_fmt
 '1' = 22
 '2' = 23
 '3' = 0
'4' = 1
'5' = 2
'6' = 3
'7' = 4
'8' = 5
'9' = 6;
 run;
 
 proc sgplot data=have;
 where hour in (22, 23, 0:5);
 vbar hour2 / stat=freq;
 format hour2 $time2_fmt.;
 run;
 
Chung-Li
Quartz | Level 8

Thanks Reeza, 

 

I agree that this is the fastest solution!

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 13103 views
  • 4 likes
  • 3 in conversation