BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
es_edu
Fluorite | Level 6

Good morning,

I'm creating a line graph to display longitudinal data for school years.  My x-axis variables are character values and I want them displayed in chronological order (2020-21 -> 2021-22 -> 2022-23).

 

Right now it is defaulting to showing the most recent years first to the left and the oldest data further to the right.  Is there a way to fix this?

es_edu_0-1723646359955.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Madelyn_SAS
SAS Super FREQ

You could try a custom sort for your category. Right click the data item on the Data pane and select Custom Sort,

View solution in original post

2 REPLIES 2
ballardw
Super User

Easiest to ensure chronological order is to use DATES.

If that isn't possible (though should be) then numeric values.

 

I deal with school year data where the reports want to see "year" values similar to your 2021-22.

If the data is already summarized I use one of the values for year such as 2021 to represent the start of the "year". Then have a custom format to display the the value as 2021-22 as needed.

So extract the first part that variable into a numeric with code in a data step like : yearnum = input(scan(yearvar,2,'-'),f4.);

Then use this to create a format,

data syearcontrol;
   fmtname = 'Syear';
   type = 'N';
   do start=1990 to 2200;
      label = catx('-',start,put( mod(start+1,100),z2.));
      output;
   end;
run;

proc format library=work cntlin=syearcontrol;
run;

/* test that the format was created and usable*/
data _null_;
  do year= 2000 to 2010;
    put year= syear.;
  end;
run;

Use whatever you think useful in the Syearcontrol data step though having a couple hundred years more than you expect may not hurt just in case. Excercise for the interested reader to add a last observation with HLO set to 'O' with a label of "Out of range" or similar value.

The last data step writes examples to the log for a small range of values.

Use the Syear format as either the default for the variable or just for use in the graph.

 

Note: you will need to either recreate the format each session you want to use it OR place the format into a permanent library that your FMTSEARCH SAS system option sees.

Madelyn_SAS
SAS Super FREQ

You could try a custom sort for your category. Right click the data item on the Data pane and select Custom Sort,

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Tips for filtering data sources in SAS Visual Analytics

See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 465 views
  • 0 likes
  • 3 in conversation