Data visualization with SAS programming

DISCRETEORDER=DATA (PROC SGPLOT)

Reply
Occasional Contributor cws
Occasional Contributor
Posts: 18

DISCRETEORDER=DATA (PROC SGPLOT)

I am trying to produce a scatter plot where the y-axis is ordered in ascending order instead of formatted values. I have sorted the data and used :
yaxis grid discreteorder=data;

But it makes no difference. I see there is a technical report (problem note 31189) on this for dot plots and the work around suggested uses the SCATTER statement in PROC SGPLOT . However I am already using scatter. I tried running the two pieces of code on the technical support page and got the same results with both.
SAS Employee
Posts: 980

Re: DISCRETEORDER=DATA (PROC SGPLOT)

Perhpas "proc gplot" will do what you're wanting(?)
SAS Super FREQ
Posts: 925

Re: DISCRETEORDER=DATA (PROC SGPLOT)

If your data is numeric, you may also need to set TYPE=DISCRETE on the YAXIS statement.

-- Dan
Occasional Contributor cws
Occasional Contributor
Posts: 18

Re: DISCRETEORDER=DATA (PROC SGPLOT)

I tried that- it makes no difference. I also tried running both bits of suggested code in the fix on the SAS support pages (i.e. for problem note 31189) and got the same output both times.
SAS Employee
Posts: 980

Re: DISCRETEORDER=DATA (PROC SGPLOT)

Can you post up a small example (data & code)?
SAS Super FREQ
Posts: 925

Re: DISCRETEORDER=DATA (PROC SGPLOT)

Can you post the procedure code snipit? Also post the data type of your variables.

Thanks!
Dan
Occasional Contributor cws
Occasional Contributor
Posts: 18

Re: DISCRETEORDER=DATA (PROC SGPLOT)

Here is some data and the code I am using. It is a plot of estimates with CIs for several variables (identified by CNO). I wanted the plot to order cno by ratio rather than numeric order of cno.

data aplot;
input cno ratiolowercl ratioestimate ratiouppercl;
datalines;
10 0.55541 2.05934 7.63559
8 0.45885 1.31806 3.78619
6 0.33371 1.04236 3.25585
9 0.23368 0.81469 2.84031
13 0.39450 0.80129 1.62756
3 0.19638 0.78082 3.10455
12 0.08985 0.72433 5.83897
2 0.35373 0.65671 1.21921
5 0.29766 0.65028 1.42060
4 0.25529 0.63470 1.57801
7 0.07987 0.33106 1.37215
run;
proc sort data=aplot;
by descending ratioestimate;
run;
proc sgplot data=aplot;
yaxis grid type=discrete discreteorder=data;
xaxis type=log logbase=10;
scatter y=cno x=ratioestimate /xerrorlower=ratiolowercl xerrorupper=ratiouppercl ;
refline 1/axis=x label='Ratio=1';
run; I have just discovered that if I use a character variable instead of CNO (numeric) it works correctly. Before I was assigning a character format to the numeric variable CNO.


Message was edited by: cws
SAS Super FREQ
Posts: 925

Re: DISCRETEORDER=DATA (PROC SGPLOT)

The solution is to create a second CNO column that is character and use that column for the Y variable. The ODS Graphics system is forcing the numeric values into ascending order. Making them character get around this. The DISCRETEORDER=DATA option currently works with only bar charts, line charts, dot plots, and box plot plots, so you can remove it for this example.

Thanks!
Dan
Occasional Contributor cws
Occasional Contributor
Posts: 18

Re: DISCRETEORDER=DATA (PROC SGPLOT)

Thanks Dan.

Got there in the end!
Ask a Question
Discussion stats
  • 8 replies
  • 1234 views
  • 0 likes
  • 3 in conversation