BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BLarson
Obsidian | Level 7

Hello, I have the below program where I have created a map output.  I also created 4 patterns as well as 4 catagories in my Proc Format statement.  My question is, instead of assigning a pattern can I assign a color depending on the underlying value.  so for low - < .25 I would like this to always be green and so on, with the .75 - high always be red.  Thank you.

 

DATA WORK.MYMAP;

SET MAPSGFK.US;

WHERE STATECODE NOT IN ('AK', 'HI');

RUN;

 

*create format for map output;

PROC FORMAT;

VALUE ITP

low - < .25 = '< 25%'

.25 - < .50 = '25 - 49 %'

.50 - < .75 = '50 - 74%'

.75 - high = '> 75%'

;

RUN;

PATTERN1 V=S c=green;

PATTERN2 V=S c=yellow;

PATTERN3 V=S C=blue;

PATTERN4 V=S C=Red;

PATTERN5 V=MS c=lightgrey;

 

PROC GMAP DATA=WORK.SALESKPI_APPLICATION_OUT1 MAP=WORK.MYMAP ALL ;

BY LVL1_SALES_CHANNEL;

ID STATECODE;

BLOCK ITP_PD_PCT / DISCRETE WOUTLINE=1 COUTLINE=black CEMPTY=BLACK cblock=black blocksize=4 shape=cylinder

xview=0.75 yview=-1.0 zview=3.5;

label ITP_PD_PCT = 'ITP Past Due %';

FORMAT ITP_PD_PCT ITP.;

RUN;

QUIT;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

How many different combinations are you going to deal with? If it is only a few then you may be able to make a macro that that takes as one of the parameters the appropriate format, which you would still need for the grouping and include code to check the format and assign the matching legend values.

 

Semi pseudocode of what I am thinking;

%macro mymap (dataset=, mapset=, mapvar=, mapvarfmt = );

%if %upcase(&Mapvarfmt) = ITP %then %do;
   PATTERN1 V=S c=green;
   PATTERN2 V=S c=yellow;
   PATTERN3 V=S C=blue;
   PATTERN4 V=S C=Red;
%end;

%if %upcase(&Mapvarfmt) = OTHFMT %then %do;
   PATTERN1 V=S c=green;
   PATTERN2 V=S c=yellow;
   PATTERN3 V=S C=Red;
%end;

/* the actual gmap code goes here*/
%mend;

/* call similar to */
%mymap (dataset=WORK.SALESKPI_APPLICATION_OUT1 , mapset=WORK.MYMAP , mapvar=ITP_PD_PCT , mapvarfmt = ITP)

Or maybe instead of the actual format name to assign the pattern statements a separate NumLegendLines parameter and have groups of pattern statements corresponding to 3, 4, 5, 6 or similar groups you might reuse. This would have the advantage of only needing to know the number breaks in your data to display if you use many formats with slightly different values between those upper and lower bounds.

 

View solution in original post

5 REPLIES 5
ballardw
Super User

What I think you are asking is similar to the ATTRMAP attribute dataset for variables for SG graphing procedures to keep characterstics that can be "automatically" applied without defining them in each procedure call.

 

GMAP is basically the old device approach and does not support that approach. If the bounds don't change you can use the format you have already defined with multiple variables.

 

If you always want to use 4 colors, a custom ODS style could be created to modify the default colors  and would be used in the order of the PATTERN statements that you are currently defining but not attached to a specific range of values.

 

Or are you trying to have the color for those ranges when you may have more or fewer response categories?

 

You may need to be a bit more specific about what you are attempting to achieve.

BLarson
Obsidian | Level 7

Good Afternoon

Thank you for the feedback.  yes what I am trying to achieve is as you stated "trying to have the color for those ranges when you may have more or fewer response categories?". 

BLarson
Obsidian | Level 7
Good Afternoon

Thank you for the feedback. yes what I am trying to achieve is as you stated "trying to have the color for those ranges when you may have more or fewer response categories?".




ballardw
Super User

How many different combinations are you going to deal with? If it is only a few then you may be able to make a macro that that takes as one of the parameters the appropriate format, which you would still need for the grouping and include code to check the format and assign the matching legend values.

 

Semi pseudocode of what I am thinking;

%macro mymap (dataset=, mapset=, mapvar=, mapvarfmt = );

%if %upcase(&Mapvarfmt) = ITP %then %do;
   PATTERN1 V=S c=green;
   PATTERN2 V=S c=yellow;
   PATTERN3 V=S C=blue;
   PATTERN4 V=S C=Red;
%end;

%if %upcase(&Mapvarfmt) = OTHFMT %then %do;
   PATTERN1 V=S c=green;
   PATTERN2 V=S c=yellow;
   PATTERN3 V=S C=Red;
%end;

/* the actual gmap code goes here*/
%mend;

/* call similar to */
%mymap (dataset=WORK.SALESKPI_APPLICATION_OUT1 , mapset=WORK.MYMAP , mapvar=ITP_PD_PCT , mapvarfmt = ITP)

Or maybe instead of the actual format name to assign the pattern statements a separate NumLegendLines parameter and have groups of pattern statements corresponding to 3, 4, 5, 6 or similar groups you might reuse. This would have the advantage of only needing to know the number breaks in your data to display if you use many formats with slightly different values between those upper and lower bounds.

 

BLarson
Obsidian | Level 7

Thank you very much.  I will work with that and let you know how it turns out.  Again I greatly appreciate your guidance.

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
  • 5 replies
  • 1295 views
  • 1 like
  • 2 in conversation