BookmarkSubscribeRSS Feed
Abishekaa
Obsidian | Level 7
   proc sgplot data=temp1;
   		series x=ageVisit y=aval / group=subjeye lineattrs=(pattern=solid)
         attrid=group2 ;
	   	xaxis label='axis (years)';
	   	yaxis label="axis (paramter)";
	   	styleattrs datacontrastcolors=(red blue green);
	run;

How can I add a legend for the attrid in this plot? I want a legend that shows the three groups and colors of the group2 variable

2 REPLIES 2
ballardw
Super User

ATTRID option specifies the value of the ID variable in a discrete attribute data set. It basically indicates which set ov values to use for a given group variable as the data set could contain the multiple sets of descriptions for the same VALUE

Since your code does not show the use of a discrete attribute map data set, which would be indicated by the use of the DATTRMAP option on the Proc Sgplot statement, you question doesn't make much sense as phrased. The default legend would have the values of the Group variable. The color or other options specified for each value would be in the DATTRMAP data set where the ID variable has the value "group2".

 

I would strongly suggest looking in the online help "Using Discrete Attribute Map Sets".

Ksharp
Super User

Your code was NOT right. You should remove statement "styleattrs" and add option "dattrmap=".

data dattrmap;
input id $ value $ linecolor $;
cards;
group2 1 red
group2 2 blue
group2 3 green
run;

data temp1;
input subjeye ageVisit aval;
cards;
1 10 10
1 11 11
1 12 12
2 20 20
2 22 22
2 24 24
3 30 30
3 32 32
3 34 34
;

proc sgplot data=temp1 dattrmap=dattrmap;
   		series x=ageVisit y=aval / group=subjeye lineattrs=(pattern=solid)
         attrid=group2 ;
	   	xaxis label='axis (years)';
	   	yaxis label="axis (paramter)";
	run;

Ksharp_0-1768892283477.png

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 141 views
  • 0 likes
  • 3 in conversation