BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
FLETCHSAS
Calcite | Level 5

Hello

     Whenever I run my program for a vertical bar chart using "sex" as the variable i keep getting this error. I tried using a PROC SORT statement before the PROC GCHART statement but keep getting this error message when I run the program.

PROC GCHART data=ACS;

     TITLE "Average Age conditional on Sex";

     VBAR age / group=sex

     DISCRETE

     TYPE=MEAN SUMVAR=AGE;

RUN;

QUIT;


ERROR: Data set WORK.ACS is not sorted in ascending sequence. The current BY group has SEX = 2 and the next BY group has SEX = 1.

If anyone can show me where I am messing up it would be greatly appreciated.

--Michael FLetcher

1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

The error message mentions a 'by group', but I don't see a by-statement in your SAS code.

Are you showing us all the code, or does your code perhaps have 'by sex' in it?

Here's some sample code, using sashelp.class, that reproduces a similar error using a 'by' statement...

data foo; set sashelp.class;

run;

PROC GCHART data=foo;

by sex;

     TITLE "Average Age conditional on Sex";

     VBAR age / group=sex

     DISCRETE

     TYPE=MEAN SUMVAR=AGE;

RUN;

And here's one possible work-around:

proc sort data=sashelp.class out=foo;

by sex;

run;

PROC GCHART data=foo;

by sex;

     TITLE "Average Age conditional on Sex";

     VBAR age / group=sex

     DISCRETE

     TYPE=MEAN SUMVAR=AGE;

RUN;

View solution in original post

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

This could be possible if the sex variable is character. Then it may not sort properly.

Thanks,

Jag

Thanks,
Jag
GraphGuy
Meteorite | Level 14

The error message mentions a 'by group', but I don't see a by-statement in your SAS code.

Are you showing us all the code, or does your code perhaps have 'by sex' in it?

Here's some sample code, using sashelp.class, that reproduces a similar error using a 'by' statement...

data foo; set sashelp.class;

run;

PROC GCHART data=foo;

by sex;

     TITLE "Average Age conditional on Sex";

     VBAR age / group=sex

     DISCRETE

     TYPE=MEAN SUMVAR=AGE;

RUN;

And here's one possible work-around:

proc sort data=sashelp.class out=foo;

by sex;

run;

PROC GCHART data=foo;

by sex;

     TITLE "Average Age conditional on Sex";

     VBAR age / group=sex

     DISCRETE

     TYPE=MEAN SUMVAR=AGE;

RUN;

DanH_sas
SAS Super FREQ

I had that same question that Robert stated above. That message is typically a BY-group message. However, I do have a more general question. Is that code going to give you what you want? Here is your code:

PROC GCHART data=ACS;

     TITLE "Average Age conditional on Sex";

     VBAR age / group=sex

     DISCRETE

     TYPE=MEAN SUMVAR=AGE;

RUN;

QUIT;

Based on your title, you are looking for the average age based on sex. However, the average will always be the same as the categorical value in this graph because both the categorical variable and the response variable are "age". The mean is computed for each age in "age", which will always give you the age back. Perhaps your desire was to do something more like this:

PROC GCHART data=ACS;

     TITLE "Average Age conditional on Sex";

     VBAR sex /

     DISCRETE

     TYPE=MEAN SUMVAR=AGE;

RUN;

QUIT;

I believe this will give you the average age conditional on sex.

Hope this helps!

Dan

FLETCHSAS
Calcite | Level 5

Thank you Robert. Hit the nail right on the head runs error free now. Hope all is well.

--MFletcher

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 2075 views
  • 7 likes
  • 4 in conversation