BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
cluelesssas
Fluorite | Level 6

 

sas_order.png

The table is ordered in decreasing frequency from top to bottom, but the plot is ordered in increasing frequency from bottom to top. I understand this is probably b/c the y axis value is increasing in that direction, but it still just looks suboptimal viewing the table and plot together. Is there any way to make the ordering between table and plot consistent? As a side question, even though I set a label, is there any way to not have the original variable name be used (and especially so prominently in the plot title) - there could be times when the original variable name is even uglier (eg, from ADaM/SDTM data). Here is my code

ods graphics on;
proc freq data=pg1.storm_final order=freq;
	tables StartDate / plots=freqplot(orient=horizontal scale=percent);
	format StartDate monname.;
	label StartDate='Storm Month';
run;

Example data comes from this SAS course:  https://learn.sas.com/course/view.php?id=118

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

I check the DOC, there is not such option ORDER= in FREQPLOT.

So the most convenient way is using PROC SGPLOT to replace the default graph of proc freq.

 

proc freq data=sashelp.heart order=freq;
	tables bp_status ;
run;

title 'Whatever';
proc sgplot data=sashelp.heart;
hbar bp_status/stat=percent categoryorder=resdesc;
xaxis grid;
run;

Ksharp_0-1761546386119.png

 

View solution in original post

4 REPLIES 4
quickbluefish
Barite | Level 11

Are you sure you don't just want the months displayed in chronological order instead of by frequency?  Personally, I think that's going to confuse people.  In any case, I would use SGPLOT instead of tying yourself down with PROC FREQ:

 

proc sgplot data=test noautolegend;
format startdate monname.;
vbar startdate / datalabel categoryorder=respasc;
xaxis label="Storm Month";
run;

If you want it ordered chronologically, just remove the 'categoryorder' part.  And use HBAR rather than VBAR if you want the bars to be horizontal.

 

Tom
Super User Tom
Super User

I would assume it is because the coder that made the plot decided it looked better when the frequencies are in ascending order.

 

Note that whoever made the code that makes that PLOT did so some 30 years after the table output was coded.

Ksharp
Super User

I check the DOC, there is not such option ORDER= in FREQPLOT.

So the most convenient way is using PROC SGPLOT to replace the default graph of proc freq.

 

proc freq data=sashelp.heart order=freq;
	tables bp_status ;
run;

title 'Whatever';
proc sgplot data=sashelp.heart;
hbar bp_status/stat=percent categoryorder=resdesc;
xaxis grid;
run;

Ksharp_0-1761546386119.png

 

cluelesssas
Fluorite | Level 6

Thx KSharp.

Here is the code I ended up using (just a small nitpick that the LOG picked up: resdesc -> respdesc ie you forgot the p)

title 'Distribution of Storm Month';
proc sgplot data=pg1.storm_final;
	hbar StartDate/stat=percent categoryorder=respdesc;
	format StartDate monname.;
	label StartDate='Storm Month';
	xaxis grid;
run;
title;

The course I linked above advertised how you can assign temporary formats and labels within PROC steps. However in this case I need to use it in both FREQ and SGPLOT so I should probably move those to the DATA step

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
  • 4 replies
  • 431 views
  • 3 likes
  • 4 in conversation