Data visualization with SAS programming

INCLUDE ALL LEGEND ENTRY

Reply
New Contributor
Posts: 2

INCLUDE ALL LEGEND ENTRY

Hai all,

I have a question.How can I include all the legend entries in graph even though  the legend group not include in the graph?

As an example I took coding from SAS website:

You can apply a format to a group column to change the legend entry labels or the number of classification levels. The ordering of the legend entries is based on the order of the pre-formatted group values. In the following example, the data is sorted in ascending order, so the legend entry order is "Pre-Teen" "Teen" "Adult." Because there are no adults, "Adult" does not appear in the graph.

proc format;

  value teenfmt

  low-12  = "Pre-Teen"

  13-19   = "Teen"

  20-high = "Adult";

run;

proc sort data=sashelp.class out=class;

  by age;

run;

proc sgrender data=class template=order;

  format age teenfmt.;

  dynamic

    title="Formatted Order of Legend Entries";

run;

Super Contributor
Posts: 252

Re: INCLUDE ALL LEGEND ENTRY

Hi, you should be able to achieve what you want by using Discrete Attribute Maps. What version of SAS have you got, and can you send me the GTL code for the "Order" template that you have created?

New Contributor
Posts: 2

Re: INCLUDE ALL LEGEND ENTRY

SAS link that I refer: SAS/GRAPH(R) 9.2: Graph Template Language User's Guide, Second Edition

I used SAS 9.4.

Below is my real coding:

* example 2;

* select an empty pattern (v=e) and a title;

pattern v=e;

title 'EXAMPLE #2 ';

proc gmap

map=maps.malaysia

data=maps.malaysia (obs=1)

all;

id id;

choro id / nolegend;

run;

quit;

proc format;

value API_

0 - 50 = '0 - 50'

51 - 100 = '51 - 100'

101 - 200 = '101 - 200'

201 - 300 = '201 - 300'

301 - high = '301 >'

;

run;

data malaysia;

input id API @@;

datalines;

1 38

2 49

3 41

4 38

5 43

6 49

7 26

8 29

9 46

10 64

11 32

12 47

13 45

14 44

15 39

16 34

17 47

18 55

19 43

20 55

21 32

22 54

23 53

24 48

;

run;

* fill patterns for the map areas ;

pattern1 v=s c=green;

pattern2 v=s c=yellow;

pattern3 v=s c=orange;

pattern4 v=s c=maroon;

pattern5 v=s c=red;

proc gmap

data=malaysia

map=maps.malaysia;

id id;

choro API / discrete;

format API API_.;

title ' January 2005';

run;

and the other problem is, how can I fix the color pattern  belong to the specific scale? I mean

0 - 50 = '0 - 50' I want this in green

51 - 100 = '51 - 100'  I want this in yellow

101 - 200 = '101 - 200' Orange

201 - 300 = '201 - 300' Maroon

301 - high = '301 >' Red

SAS Super FREQ
Posts: 864

Re: INCLUDE ALL LEGEND ENTRY

PROC GMAP is a SAS/Graph proc, and not part of GTL or the SG procedures. Therefore, the discrete attribute map approach will not work. I did discuss this situation with a colleague that had a interesting way to make it happen. Use ID=0 and create observations that contain one value from each range. That way, the observation has no impact on the map, but the legend will show all ranges. For your example, you will need 5 additional observations.

Hope this helps!

Dan

SAS Employee
Posts: 963

Re: INCLUDE ALL LEGEND ENTRY

One word of caution when adding 'fake' observations to the data ... the "best practice" is probably to create a separate dataset just for the graph, and then throw it away, rather than adding the fake observations to the real dataset. If you add the observations to the real dataset, and later do any graphs or calculations that perform a frequency count, the fake observations could cause the frequency values to be wrong.

Grand Advisor
Posts: 9,748

Re: INCLUDE ALL LEGEND ENTRY

Another approach would be to make an Annotate data set for the legend information and suppress the actual legend. This has some additional flexibility at the typical expense of somewhat more work.

Super Contributor
Posts: 252

Re: INCLUDE ALL LEGEND ENTRY

Only seeing this now. Dan's hints should help.

Thanks!

Post a Question
Discussion Stats
  • 6 replies
  • 434 views
  • 3 likes
  • 5 in conversation