Calcite | Level 5

## How to add more than one subgroup in proc gchart?

Hi,

I am new to SAS. It would be very great full if someone can help me to know how to pass more subgroup to a gchart  in either of vbar or hbar option.

Abhishek

1 ACCEPTED SOLUTION

Accepted Solutions
Pyrite | Level 9

## Re: How to add more than one subgroup in proc gchart?

OK.

So, in your data set, each row is a person.

For example, for row one, the person marked the highest value M1, then M5, then M6, and finally M22 without any further models.

The second person marked M1 as the highest, then M3, then M5, M21,M12, and M18.

Now,

you would like to plot this information, such that it shows for M1 there were 3 persons that find it highvalue (or whatever), for M5 there were 5 persons...for M67 there were 4.

So, your graph should have on the x-axis the Model number 1...70...

and the bars should be the number of people?

Am I getting this right?

Anca.

Here is code that would do what I said:

data have;

infile datalines missover;

input id Highvalue1 \$    Highvalue2 \$    highvalue3 \$     highvalue4 \$     highvalue5 \$    highvalue6 \$;

datalines;

1 m1                    m5          m67               m22

2 m1                    m3          m5                m21          m12               m18

3 m1                    m23         m12               m45

4 m5                    m10         m5                m22          m10               m67

5 m5                    m6          m8                m56          m35

6 m5                    m12         m45               m56

7 m37                   m45         m56               m67          m70

8 m67                   m70

;

proc transpose data = have out = have_t;

var highvalue:;

by id;

run;

proc sort data = have_t;by col1;run;

data have_2;

set have_t(where = (col1 ne " "));

by col1;

retain cnt 0;

if first.col1 then cnt = 1;

else cnt ++ 1;

if last.col1;

run;

proc gchart data = have_2;

vbar col1 / sumvar = cnt discrete;

run;quit;

Nachricht wurde geändert durch: Anca tilea

4 REPLIES 4
Pyrite | Level 9

## Re: How to add more than one subgroup in proc gchart?

Hi.

You can use the subgroup statement;

goptions reset = all;

axis1 label = none value = none;

proc gchart data = sashelp.shoes;

where region = "Africa";

vbar product/sumvar = stores group = subsidiary subgroup = product discrete

maxis = axis1;

run;quit;

Does this look like something you need?

Good luck,

Anca.

Calcite | Level 5

## Re: How to add more than one subgroup in proc gchart?

Thanks Anca For the wonderful answer

Actually I am having a SAS dataset something like below:-

Highvalue1     Highvalue2     highvalue3     highvalue4     highvalue5     highvalue6

m1                    m5               m67               m22

m1                    m3               m5                   m21          m12               m18

m1                    m23            m12                   m45

m5                    m10              m5                    m22          m10               m67

m5                   m6                   m8                    m56          m35

m5                    m12               m45                    m56

m37                   m45               m56                    m67          m70

m67                    m70

This table depicts the observation of the people who has given the highest marks to some of the models out of 75 models.

Now i want to plot the graph to representing the people who has given highest marks to m1 has also given to m5 m67 m22 and so on.

If somebody can help me out in this, that would be really appreciable.

Abhishek Pathak

Pyrite | Level 9

## Re: How to add more than one subgroup in proc gchart?

OK.

So, in your data set, each row is a person.

For example, for row one, the person marked the highest value M1, then M5, then M6, and finally M22 without any further models.

The second person marked M1 as the highest, then M3, then M5, M21,M12, and M18.

Now,

you would like to plot this information, such that it shows for M1 there were 3 persons that find it highvalue (or whatever), for M5 there were 5 persons...for M67 there were 4.

So, your graph should have on the x-axis the Model number 1...70...

and the bars should be the number of people?

Am I getting this right?

Anca.

Here is code that would do what I said:

data have;

infile datalines missover;

input id Highvalue1 \$    Highvalue2 \$    highvalue3 \$     highvalue4 \$     highvalue5 \$    highvalue6 \$;

datalines;

1 m1                    m5          m67               m22

2 m1                    m3          m5                m21          m12               m18

3 m1                    m23         m12               m45

4 m5                    m10         m5                m22          m10               m67

5 m5                    m6          m8                m56          m35

6 m5                    m12         m45               m56

7 m37                   m45         m56               m67          m70

8 m67                   m70

;

proc transpose data = have out = have_t;

var highvalue:;

by id;

run;

proc sort data = have_t;by col1;run;

data have_2;

set have_t(where = (col1 ne " "));

by col1;

retain cnt 0;

if first.col1 then cnt = 1;

else cnt ++ 1;

if last.col1;

run;

proc gchart data = have_2;

vbar col1 / sumvar = cnt discrete;

run;quit;

Nachricht wurde geändert durch: Anca tilea

Calcite | Level 5

## Re: How to add more than one subgroup in proc gchart?

Thanks anca, It was very helpful for me

Discussion stats
• 4 replies
• 1253 views
• 0 likes
• 2 in conversation