For x-axis, I want to correct the order to: Week 0, Week 8, Week 16, Week 24, Week 32 instead of otherwise.
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.
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?
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".
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.
(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;
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.
@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.
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.
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.