BookmarkSubscribeRSS Feed
PaalNavestad
Pyrite | Level 9

The folowing code produces the nearly the same results but the gradlegend is completly misleading in the first graph. Can somebody please explain and suggest a solution when uing discrete variable to produce the gradlegend?

data class;
 set sashelp.class;
 if weight < 85 then wn=0;
 else wn=1;

run;

data weightdisc;
retain id "wdisc";
length min $ 5 max $ 5;
input min $ max $ color $ altcolor $;
datalines;
0 0    Bio Bio
1 1    bro bro


;
run;

ods graphics on/width=800 px height=600 px;
proc sgplot data=class rattrmap=weightdisc;
	vbar name/ response=Weight colorresponse=wn rattrid=wdisc ;
run;
data weightrange;
retain id "wrange";
length min $ 5 max $ 5;
input min $ max $ color $ altcolor $;
datalines;
0 85    Bio Bio
85 150    bro bro

;
run;
proc sgplot data=class rattrmap=weightrange;
	vbar name/ response=Weight colorresponse=weight rattrid=wrange ;
run;

The first result look like this. As can be seen the gradlegend is completly wrongdiscLegend.PNG

Second option look like this

Rangelegend.PNG

As can be seen the legend is logical.

 

The second option can not be used in all cases where you have a process in determing this.

 

There are solutions to the problem using attribute map instead. However that usually means using a dummy group variable for vbar and cannot be used for scatter plots.

1 REPLY 1
ballardw
Super User

Is your question "If I provide a poorly designed attribute map why does SAS display it as I instructed?" Your actual question is not clear.

 

 

Any tool has a learning curve. You have learned that the first approach may not be idea for your purpose and not to use it.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 712 views
  • 0 likes
  • 2 in conversation