BookmarkSubscribeRSS Feed
avner
Calcite | Level 5

Hi all,

 

I want to get the total_roots distribution by  account_range,like pic below, but the x-axis order is not what I want.  thanks a lot for help.

 my data looks like below:

Obs versiontype           account_num      roots           account_range 
1  ads                      2                1                  0-100 
2  ads                      3                1                  0-100 
3  user_define              3                1                  0-100 
4  user_define              4                1                  0-100 
5  customized               7                1                  0-100 
6  ads                      8                1                  0-100 
7  customized               9                1                  0-100 
8  basic                    13               1                  0-100 
9  advanced                 15               1                  0-100 
10 advanced                 16               1                  0-100 

main program I get the graph is below:

	proc format library = library;
	value Account_Range	
				low-100='0-100'
		                101-200='101-200'
				201-300='201-300'
				301-400='301-400'
				401-500='401-500'
				501-600='501-600'
				601-700='601-700'
				701-800='701-800'
				801-900='801-900'
				901-1000='901-1000'
				1001-2000='1000-2000'
				2001-high='2001+';
	     
	run;

        data client.tmp_account_format;
             set client.tmp_account_num_roots;
             account_range = put(account_num,account_range.);
         run;

         proc sql;
              create table client.tmp_accounts as 
              select versiontype,account_range,sum(roots)as total_roots 
              from client.tmp_account_format 
              group by versiontype,account_range 
              ;
          quit;

          proc gplot data=client.tmp_accounts ;
               plot total_roots * account_range ;
               where versiontype in ('ads','basic','advanced','customized','user_define');
               by versiontype; 
         run;
         quit;

 

 

the result I get like below: I guess the x-axis is not well ordered is mainly because the put function converts the account_range to character, so SAS sort the account_range like below, but can I change it? move the 1001-2000 and 2000+ to the right of the chart.

Thanks a lot !

2.png

 

1 REPLY 1
ballardw
Super User

Try doing the plot with the NUMERIC variable and use a FORMAT statement in GPLOT to associate the format with the variable.

 

OR pay attention to such sort order issues when building the format to pad the leading values with blanks

roc format library = library;
   value Account_Range	
   low-100  ='   0-100'
   101-200  =' 101-200'
   201-300  =' 201-300'
   301-400  =' 301-400'
   401-500  =' 401-500'
   501-600  =' 501-600'
   601-700  =' 601-700'
   701-800  =' 701-800'
   801-900  =' 801-900'
   901-1000 =' 901-1000'
   1001-2000='1000-2000'
   2001-high='2001+'
   ;
	     
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1136 views
  • 0 likes
  • 2 in conversation