🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Quartz | Level 8

## 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:

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

1 ACCEPTED SOLUTION

Accepted Solutions
Quartz | Level 8

## Re: Change the x-axis order in SGPLOT

xaxis display=(nolabel) discreteorder=data;

5 REPLIES 5
Diamond | Level 26

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

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.

Quartz | Level 8

## Re: Change the x-axis order in SGPLOT

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

Diamond | Level 26

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

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

Quartz | Level 8