DATA Step, Macro, Functions and more

Change the x-axis order in SGPLOT

Accepted Solution Solved
Reply
Contributor
Posts: 70
Accepted Solution

Change the x-axis order in SGPLOT

i have table as below, How to change the order to display in month order

 

Table:

 

input Affected_CI count;
datalines;
'54JFY5 Prtfolios ledger -  January'    10
'54JFY5 Prtfolios ledger -  February'    17
'66ABC5 Fund Data Correction -  -March'    7;
run;

 

result as below:

st.jpg

 

 

 

expecting in order January,February and march x-as order.

 

 

 

 


Accepted Solutions
Solution
‎04-25-2018 03:21 PM
Contributor
Posts: 70

Re: Change the x-axis order in SGPLOT

resolved by adding

 

xaxis display=(nolabel) discreteorder=data;

View solution in original post


All Replies
Super User
Super User
Posts: 9,840

Re: Change the x-axis order in SGPLOT

You can use the search bar on the main page to search for topics similar to your question.

https://communities.sas.com/t5/forums/searchpage/tab/message?advanced=false&allow_punctuation=false&...

 

The simplest method is to change the xaxis values to be numbers, and to that field apply a format, so the data sorts per number and displays the formatted version:

proc format;
  value t 
    1='54JFY5 Prtfolios ledger -  January' 
    2='54JFY5 Prtfolios ledger -  February'
    3='66ABC5 Fund Data Correction -  -March';
run;

data inter;
  set have;
  if affected_ci='54JFY5 Prtfolios ledger -  January' then xasxisvar=1;
  if ...;
  format xaxisvar t.;
run;

Then use xaxisvar on your xaxis.

Contributor
Posts: 70

Re: Change the x-axis order in SGPLOT

The app names are not constant.they are generated on different queries.

Super User
Super User
Posts: 9,840

Re: Change the x-axis order in SGPLOT

Then dynamically create the proc format step.

data _null_;
  set your_query_results end=last;
  if _n_=1 then call execute('proc format; value t ');
call execute(strip(put(_n_,best.),'=',strip(quote(query_result_text)," ");
if last then call execute(';run;');
run;

I can only answer what is provided.

Super User
Posts: 13,941

Re: Change the x-axis order in SGPLOT

An alternate approach would be have an actual DATE value for the xaxis (fixes the sort issue) using an appropriate format for the display and then have a separate variable, possibly fund, that contains the other text like "54JFY5 Prtfolios ledger" and use that as a group variable and groupdisplay=cluster.

Yes this would move some of the information from the Axis to a Legend. Depending on the values involved that may be easier to manage long values.

 

I have to say that having the same color appear for two apparently unrelated data bits

54JFY5 Prtfolios ledger and 66ABC5 Fund Data Correction is really confusing.

Solution
‎04-25-2018 03:21 PM
Contributor
Posts: 70

Re: Change the x-axis order in SGPLOT

resolved by adding

 

xaxis display=(nolabel) discreteorder=data;

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 173 views
  • 1 like
  • 3 in conversation