BookmarkSubscribeRSS Feed
N_H_A_R
Calcite | Level 5

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;

6 REPLIES 6
djrisks
Barite | Level 11

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?

N_H_A_R
Calcite | Level 5

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

DanH_sas
SAS Super FREQ

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

GraphGuy
Meteorite | Level 14

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.

ballardw
Super User

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.

djrisks
Barite | Level 11

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

Thanks!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1248 views
  • 3 likes
  • 5 in conversation