Data visualization with SAS programming

GCHART Error when running character variable "Sex"

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

GCHART Error when running character variable "Sex"

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


Accepted Solutions
Solution
‎11-03-2014 08:41 AM
SAS Employee
Posts: 963

Re: GCHART Error when running character variable "Sex"

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


All Replies
Super User
Posts: 993

Re: GCHART Error when running character variable "Sex"

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

Thanks,

Jag

Thanks,
Jag
Solution
‎11-03-2014 08:41 AM
SAS Employee
Posts: 963

Re: GCHART Error when running character variable "Sex"

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;

SAS Super FREQ
Posts: 864

Re: GCHART Error when running character variable "Sex"

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

Occasional Contributor
Posts: 5

Re: GCHART Error when running character variable "Sex"

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

--MFletcher

Post a Question
Discussion Stats
  • 4 replies
  • 742 views
  • 7 likes
  • 4 in conversation