Data visualization with SAS programming

sgplot xaxis NOT sorted for all group values

Accepted Solution Solved
Reply
Contributor
Posts: 55
Accepted Solution

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.

profile.PNG


Accepted Solutions
Solution
‎08-16-2017 12:18 PM
Super User
Posts: 19,058

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. 

 

 

View solution in original post


All Replies
Solution
‎08-16-2017 12:18 PM
Super User
Posts: 19,058

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. 

 

 

Contributor
Posts: 55

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

Contributor
Posts: 55

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) ;

Contributor
Posts: 55

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... 

Thanks a lot in advance for your help

Nasser

Contributor
Posts: 55

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
Posts: 11,114

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;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 191 views
  • 3 likes
  • 3 in conversation