Data visualization with SAS programming

How to add more than one subgroup in proc gchart?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

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.

Thanks in Advance

Abhishek


Accepted Solutions
Solution
‎01-03-2014 10:38 AM
Super Contributor
Posts: 543

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

View solution in original post


All Replies
Super Contributor
Posts: 543

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.

Occasional Contributor
Posts: 7

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.

Thanks in Advance,

Abhishek Pathak

Solution
‎01-03-2014 10:38 AM
Super Contributor
Posts: 543

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

Occasional Contributor
Posts: 7

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

Thanks anca, It was very helpful for me

Post a Question
Discussion Stats
  • 4 replies
  • 465 views
  • 0 likes
  • 2 in conversation