Lapis Lazuli | Level 10

## sgplot xaxis NOT sorted for all group values

Hello,

I use proc sgplot . the group is the column "Profil" with 4 values NA, P1, P2 and P3.

the values of xaxis are N, N+1, N+2, N+3...(years)

The problem is the following : I would like that xaxis values are sorted like N, N+1, N+2...N+8. but as you can notice in the enclosed picture , they are not sorted because the profiles P1 P2 and P3 have the x values N, N+1, N+2 But the NA profil has x values N+5 to N+8.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: sgplot xaxis NOT sorted for all group values

Create another variable that maps N to 0, N+1 to 1, N+2 to 2, etc.

Then use that variable as your X axis, but create a format that displays it as N, N+1.

6 REPLIES 6
Super User

## Re: sgplot xaxis NOT sorted for all group values

Create another variable that maps N to 0, N+1 to 1, N+2 to 2, etc.

Then use that variable as your X axis, but create a format that displays it as N, N+1.

Lapis Lazuli | Level 10

## Re: sgplot xaxis NOT sorted for all group values

thank you very much Reeza for you quick answer.

I create the new variable but only 0 2 4 6 8 are displayed. 1 3 5 7 are missing on the x axis

Lapis Lazuli | Level 10

## Re: sgplot xaxis NOT sorted for all group values

I succed to get the correct values in x axis by using min max values in variable and then I can do this :

xaxis display = (nolabel) discreteorder = FORMATTED values=(&v_min_xaxis. to &v_max_xaxis. by 1) ;

Lapis Lazuli | Level 10

## Re: sgplot xaxis NOT sorted for all group values

Hello Reeza

I don't succeed to create a format that displays (0,1,2,3...)  as N, N+1, N+2...

Nasser

Lapis Lazuli | Level 10

## Re: sgplot xaxis NOT sorted for all group values

I succeeded to create the format like this

proc format ; picture Format_Year_Suite low-high = '00' (prefix='N + ') ; run;

and then within the proc sgplot I mentionne

format Suite_Year_4_Sort Format_Year_Suite. ;

the problem is that it works for all numbers except 0 which is not displays.

Super User

## Re: sgplot xaxis NOT sorted for all group values

Perhaps something like:

```proc format library=work;
picture Format_Year_Suite
0      = 'N' (noedit)
0<-high = '09' (prefix='N + ') ;
run;

data _null_;
do x= 0 to 10;
put x= best5. +1 x= format_year_suite.;
end;
run;```
Discussion stats
• 6 replies
• 1478 views
• 3 likes
• 3 in conversation