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

 

Greetings!

 

proc sgplot data=example noautolegend;
styleattrs datasymbols=(circlefilled );
scatter x=b y=a ;
keylegend / location=outside position=NW across=1;
run;

 

For the above code, is it possible to label the y axis using variable "CAT" to make the y-axis more meaningful? 

 

CATab
CAT112
CAT223
CAT335
CAT441
CAT556
CAT664

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I might suggest simply trying y=cat as a first simple to test code.

When a character variable is used for a yaxis like that the first alphabetic value will be closest to the x axis and be in ascending alphabetical value from bottom to top.

 

If that isn't sufficient then I would use your A and Cat values to make a format then apply the format to the A variable in the plot.

proc format;
value AtoCat
1= 'Cat 1'
2= 'Cat 2'
<repeat as needed>
;

proc sgplot data=example noautolegend;
styleattrs datasymbols=(circlefilled );
scatter x=b y=a ;
keylegend / location=outside position=NW across=1;
format a AtoCat. ;
run;

If you have LOTS of A values you may need to use a YAXIS statement to make the axis TYPE=Discrete and set a FITPOLICY=none to force all the values to have a tick mark to label.

View solution in original post

4 REPLIES 4
ballardw
Super User

I might suggest simply trying y=cat as a first simple to test code.

When a character variable is used for a yaxis like that the first alphabetic value will be closest to the x axis and be in ascending alphabetical value from bottom to top.

 

If that isn't sufficient then I would use your A and Cat values to make a format then apply the format to the A variable in the plot.

proc format;
value AtoCat
1= 'Cat 1'
2= 'Cat 2'
<repeat as needed>
;

proc sgplot data=example noautolegend;
styleattrs datasymbols=(circlefilled );
scatter x=b y=a ;
keylegend / location=outside position=NW across=1;
format a AtoCat. ;
run;

If you have LOTS of A values you may need to use a YAXIS statement to make the axis TYPE=Discrete and set a FITPOLICY=none to force all the values to have a tick mark to label.

zimcom
Pyrite | Level 9
Thank you, it works!
The reasxon I cannot use trying y=cat, becasure there is correlation between the 2 variavles, as you pointed out the alphabetical order will screw the corelation.
But the 2nd solution works perfect!
Reeza
Super User

Does a scatter plot make sense for your data? Also

Either way, another option is to list the values on the XAXIS statement but the FORMAT is definitely the better answer.

proc sql noprint;
select quote(cat) into :labels_list separated by " " from example order by a;
select quote(a) into :values_list separated by " " from example order by a;
quit;


Then add this to your PROC SGPLOT.

XAXIS VALUES = (&values_list.) VALUESDISPLAY = (&labels_list.);



zimcom
Pyrite | Level 9
Thanks @Reeza, you have been always so helpful too !!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 1544 views
  • 4 likes
  • 3 in conversation