Data visualization with SAS programming

proc gchart with blank vbars for zero frequency records

Accepted Solution Solved
Reply
Super User
Posts: 1,098
Accepted Solution

proc gchart with blank vbars for zero frequency records

Hi,

i would like to generate the vbar with proc gchart where i would like to display the blank vbar for those which are not there in data. For example, from the below data i will get the vbar char for india, japan, usa, china depending upon the number of records there are in the data, however i will need to display atleast in the label on maxis other countries but with no vbar as those countries records are not in the data. like i  need to display korea in maxis label but no vbar.

data have;

input countrycd country$;

cards;

1  india

1 india

1 india

1 india

2 japan

2 japan

3 usa

4 china

4 china

4 china

;

run;

axis1 value=('india' 'japan' 'usa' 'china' 'korea') ;

proc gchart data=have;

vbar country / discrete maxis=axis1;

run;

quit;

Thanks,

Jag

Thanks,
Jag

Accepted Solutions
Solution
‎11-30-2014 04:05 PM
SAS Super FREQ
Posts: 888

Re: proc gchart with blank vbars for zero frequency records

Instead of putting those values on the AXIS statement, put them on the MIDPOINTS option of the VBAR statement:

proc gchart data=have;

vbar country / discrete midpoints=('india' 'japan' 'usa' 'china' 'korea');

run;

quit;

Hope this helps!

Dan

View solution in original post


All Replies
Solution
‎11-30-2014 04:05 PM
SAS Super FREQ
Posts: 888

Re: proc gchart with blank vbars for zero frequency records

Instead of putting those values on the AXIS statement, put them on the MIDPOINTS option of the VBAR statement:

proc gchart data=have;

vbar country / discrete midpoints=('india' 'japan' 'usa' 'china' 'korea');

run;

quit;

Hope this helps!

Dan

Super User
Posts: 1,098

Re: proc gchart with blank vbars for zero frequency records

Thank you Dan for your response and it helped me.

In continuation to the above discussion, i would like to check with you , how we could create blank vbar for subgroup and group if the subgroup and group records are missing. To explain further, consider that we have category and sub-category as below

data have;

input subcat$ cat$;

cards;

A india

A india

A india

A india

B japan

B japan

C usa

A china

A china

A china

;

run;

proc gchart data=have;

vbar subcat  / discrete group=cat  subgroup=subcat ;

run;

quit;

Capture.JPG

This generates a graph as above, however if would like to create a blank vbar for korea with same subgroups. For this , should i need to create dummy records for korea in the data

or is there anything similar to midpoints. Please suggest.

Thanks,

Jag

Thanks,
Jag
SAS Super FREQ
Posts: 888

Re: proc gchart with blank vbars for zero frequency records

I think this will work for you:

axis1 order=("china" "india" "japan" "korea" "usa");

proc gchart data=have;

vbar subcat  / discrete group=cat  subgroup=subcat gaxis=axis1;

run;

quit;

Super User
Posts: 1,098

Re: proc gchart with blank vbars for zero frequency records

Thank you Dan it helped

Thanks,
Jag
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 537 views
  • 1 like
  • 2 in conversation