BookmarkSubscribeRSS Feed
gsk
Obsidian | Level 7 gsk
Obsidian | Level 7

For x-axis, I want to correct the order to: Week 0, Week 8, Week 16, Week 24, Week 32 instead of otherwise. 

 

how to change order code.JPGchange order graph.JPG

8 REPLIES 8
Reeza
Super User

Create a numerical variable with the value of week and then use a format to have it appear as WEEK 8 etc. 

 

Note that because its a character variable its sorting alphabetically, which is the correct approach. 

gsk
Obsidian | Level 7 gsk
Obsidian | Level 7

I tried this but it's still not working:


proc format;
value week_sorted
2 = "Week 8"
3 = "Week 16"
4 = "Week 24"
5 = "Week 32";
run;

proc sgpanel data = percents;
panelby VSTEST / columns=2;
format visitnum week_sorted.;
vbar visitnum / group= arm groupdisplay=cluster response=percent;
where responder='Y';

colaxis label = "Study Visit" DISCRETEORDER=data;
rowaxis label = "Percent of Subjects with >=5 mmHg BP Decrease";
label arm = "Treatment Group";
title 'Percentage of Treatment Responders by Visit and Treatment Group';
run;

 

Any idea? 

gsk
Obsidian | Level 7 gsk
Obsidian | Level 7
It worked when I sorted variables in different order:

proc sort data = visit_bp out = visit_bp_sorted;
by vstest arm visitnum visit;
run;

proc freq data= visit_bp_sorted noprint;
by vstest arm visitnum visit;
table responder / nocum out = percents;
run;
Do you know why it didn't work with
by visit vstest arm visitnum;
but worked with
by vstest arm visitnum visit;
ballardw
Super User

Or make sure the values will sort correctly for character: "Week 8" is after "Week 32" because 8 comes after 3. So use "Week 08", then the 0 comes before the 1 in "Week 16".

Jay54
Meteorite | Level 14

With ODS Graphics Procedures, there are often multiple ways to achieve the result.  In addition to the previous suggestions, you could also put the values in the order you want in your data, and use DISCRETEORDER=data on the COLAXIS.

gsk
Obsidian | Level 7 gsk
Obsidian | Level 7

(I slightly modified my code) 

I added DISCRETEORDER=data and it doesn't do anything.. What do you mean by "put the values in the order you want in your data"..?

I sorted by visit (Week 0, and so on) in proc sort and proc freq steps. 


proc sgpanel data = percents;
panelby VSTEST / columns=2;
vbar visit / group= arm groupdisplay=cluster response=percent;
colaxis display=(nolabel) DISCRETEORDER=data;
where responder='Y';
title 'Percentage of Treatment Responders by Visit and Treatment Group';
run;

Jay54
Meteorite | Level 14

Attach your sample (non-confidential) data so we can run the program to see what is going on.  It is hard to guess what is going on without your data.  

ballardw
Super User

@gsk wrote:

(I slightly modified my code) 

I added DISCRETEORDER=data and it doesn't do anything.. What do you mean by "put the values in the order you want in your data"..?

I sorted by visit (Week 0, and so on) in proc sort and proc freq steps. 


proc sgpanel data = percents;
panelby VSTEST / columns=2;
vbar visit / group= arm groupdisplay=cluster response=percent;
colaxis display=(nolabel) DISCRETEORDER=data;
where responder='Y';
title 'Percentage of Treatment Responders by Visit and Treatment Group';
run;


If you have "Week 8" proc sort unless you use the correct linguistic options will place 'Week 8' after 'Week 16' 'Week 24' and 'Week 36'.

Show us the Proc Sort.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 5069 views
  • 7 likes
  • 4 in conversation