BookmarkSubscribeRSS Feed
hellohere
Pyrite | Level 9

Say here is one single line y=sin(x). need to plot

[0,2*pi] with color=red and thickness=1.5

[2*pi,5*pi] with color=lime and thickness=2.0

OW color=green and thickness=1

 

How to do it?!

 

3 REPLIES 3
Quentin
Super User

Please provide a DATA step to generate the data, and code to generate the basic plot (SGPLOT?).

 

I would think you could add a GROUP variable to your data, with 3 levels, and use that as a /group option on your plot statement.

The Boston Area SAS Users Group is hosting free webinars!

Register now at https://www.basug.org/events.
ballardw
Super User

Which interval does 2*pi actually belong? The way you have stated the first two intervals with closed end it is defined as belonging to both intervals. One of the intervals needs to be open.

 


@hellohere wrote:

Say here is one single line y=sin(x). need to plot

[0,2*pi] with color=red and thickness=1.5

[2*pi,5*pi] with color=lime and thickness=2.0

OW color=green and thickness=1

 

How to do it?!

 


And what attributes for x less than 0? Is that included in the OW, which I have to guess means "otherwise"?

ballardw
Super User

My basic approach would be to add a GROUP variable for the range of values and a DATTRMAP data set since that is the easiest way to set multiple plot options .

 

Depending on your current ODS style the thickness numbers you specified may not have much visible difference.

 

Here is my approach:

data toplot;
do x= 0 to (6*constant('PI')) by 0.01;
   y=sin(x);
   if 0 le x lt (2*constant('PI')) then band=1;
   else if (2*constant('PI')) le x le (5*constant('PI')) then band=2; 
   else band=3;
   output;
end;
run;

data sinattrplot;
   input id $ value $   linecolor $ linethickness;
datalines;
sin_base  1  red    1.5
sin_base  2  lime   2.0
sin_base  3  green  1.0
;


proc sgplot data=toplot dattrmap=sinattrplot;
  series x=x y=y / attrid=sin_base group=band;
run;

Note that the names of variables in the attribute map data sets are set for the actual attributes involved and change between discrete, DATTRMAP data set, and ranged attributes, RATTRMAP data set.

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 3 replies
  • 93 views
  • 2 likes
  • 3 in conversation