BookmarkSubscribeRSS Feed
deleted_user
Not applicable
This is irritatingly simple, but I can't get it.

I have a continuous variable (age) that I have created categorical ranges for.
Partial follows:

IF REALAGE <= 3 THEN AGERANGE = "0-3";
ELSE IF 3 <= REALAGE AND REALAGE <= 5 THEN AGERANGE = "3-5";
ELSE IF 5 <= REALAGE AND REALAGE <= 8 THEN AGERANGE = "5-8" ;
ELSE IF 8 <= REALAGE AND REALAGE <= 11 THEN AGERANGE = "8-11";
ELSE IF 11 <= REALAGE AND REALAGE <= 14 THEN AGERANGE = "11-14" ;

I am plotting a single value per agerange with gplot in SASEG. I WANT the horizontal axis to read as it should (i.e. 0-3, 3-5, 5-8, 8-11, 11-14) instead it plots it out as (i.e. 0-3, 11-14, 3-5, 5-8, 8-11).

I have tried inserting proc format with the insert code option, no good.

Thoughts?
1 REPLY 1
Cynthia_sas
Diamond | Level 26
Hi,
There are several different ways to do this. The easiest might be to insert a leading space before the single digit ranges. [pre]
IF REALAGE <= 3 THEN AGERANGE = " 0-3";
ELSE IF 3 <= REALAGE AND REALAGE <= 5 THEN AGERANGE = " 3-5";
ELSE IF 5 <= REALAGE AND REALAGE <= 8 THEN AGERANGE = " 5-8" ;
ELSE IF 8 <= REALAGE AND REALAGE <= 11 THEN AGERANGE = " 8-11";
ELSE IF 11 <= REALAGE AND REALAGE <= 14 THEN AGERANGE = "11-14" ;
[/pre]
you may also need a length statement so the AGERANGE variable does not get truncated:
[pre]
length agerange $5;[/pre]
For more about the other ways to do ordering, you could contact Tech Support.
cynthia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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