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

How to create plot=desired in the image below at bottom instead two separate plots have1 and have2? Data attached in text file. Using SAS 9.4.

 

PLOT MULTIPLE AXIS.png

 

 

 

 

 

proc import datafile="...\plot.txt"
out=c.testplot
dbms=tab replace;
guessingrows=max;
run;

proc sgplot data=plot;
series x=risk_out y=mean_bias / group=agecat;
run;
proc sgplot data=plot;
series x=risk_out y=mean_bias / group=agecat;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Try this and see if you like it:

 

proc sgplot data=plot;
series x=risk_out y=mean_bias / group=agecat;
series x=risk_out y=mean_bias / group=agecat x2axis;
run;

Hope this helps!

Dan

View solution in original post

7 REPLIES 7
DanH_sas
SAS Super FREQ

Try this and see if you like it:

 

proc sgplot data=plot;
series x=risk_out y=mean_bias / group=agecat;
series x=risk_out y=mean_bias / group=agecat x2axis;
run;

Hope this helps!

Dan

Cruise
Ammonite | Level 13
Thanks a lot. Worked out. Now I'll focus on aesthetics of the plot.
Reeza
Super User

You'll need an attribute map then you can set the colors the same across the two groups, perhaps one set is dashed and the other isn't to differentiate easily...

 

https://blogs.sas.com/content/iml/2017/01/30/auto-discrete-attr-map.html

Cruise
Ammonite | Level 13
Hi Reeza, I'm curious. You said two groups (risk_in and risk_out)? I have two groups aligned with same values. So I don't need differentiation between groups. However, my lines differ by strata variable agecat. Please let me know I'm missing something
Cruise
Ammonite | Level 13

@DanH_sas

 

Hi Dan, any idea to fix the plot below? I also put the plot desired below.

 

proc sgplot data=plot /*data attached*/;  
series x=risk_out y=mean_bias / group=agecat;
series x=risk_in y=mean_bias / group=agecat x2axis;
run;

Output from above code:

 

Dan.png

Plot I need:
plot desired.png
 
DanH_sas
SAS Super FREQ

Without seeing the data, or knowing the full intent of the plot, I'm going to have to make a guess at your desired outcome. It appears that you really want to draw only RISK_OUT, but you want a secondary axis influenced by RISK_IN. If that is true, then you just need to make your RISK_IN plot fully transparent, like the following:

 

proc sgplot data=plot /*data attached*/;  
series x=risk_out y=mean_bias / group=agecat;
series x=risk_in y=mean_bias / group=agecat x2axis transparency=1;
run;

Let me know if this works for you.

 

Thanks!
Dan 

Cruise
Ammonite | Level 13

@DanH_sas

Thanks Dan.

Response variable 'mean_bias' aligns with unique reverse combination of risk_in and risk_out. So showing 'mean_bias' as a function of reverse combinations of risk_in and risk_out is the goal of the plot.

Plot desired shows that Risk_in takes 0 when Risk_out takes 1.0. These two risks are complementary to each other where max probability can not exceed 1. So, risk_in can not take 1 when risk_out takes 1. In other words, if one adds risk_in+risk_out at each increment the total always would be 1. I put in the first few observations of data where group variable was cut. But hopefully, this chunk of data would tell you the story of how my data is organized at least for the relationship between 'mean_bias' and the reverse combination of 'risk_in' and 'risk_out'. I have 62 counties. So after axis issue's solved I will have to think of panel options.

 

 

data dan;
input agecat county	risk_in	risk_out mean_bias;
datalines;
1	83	0	0.05	0.1592907908
1	83	0	0.1	0.233784996
1	83	0.05	0.1	0.233784996
1	83	0.1	0.15	0.3085880658
1	83	0.05	0.15	0.3085880658
1	83	0	0.15	0.3085880658
1	83	0	0.2	0.3837018973
1	83	0.15	0.2	0.3837018973
1	83	0.05	0.2	0.3837018973
1	3	0.1	0.2	0.3837018973
1	3	0	0.25	0.4591284108
1	3	0.15	0.25	0.4591284108
1	3	0.2	0.25	0.4591284108
1	3	0.1	0.25	0.4591284108
1	3	0.05	0.25	0.4591284108
1	3	0.1	0.3	0.5348695495
1	3	0.2	0.3	0.5348695495
1	3	0.15	0.3	0.5348695495
1	3	0.25	0.3	0.5348695495
;

proc sgplot data=dan /*data attached*/;  
series x=risk_out y=mean_bias / group=agecat;
series x=risk_in y=mean_bias / group=agecat x2axis transparency=1;
run;

Desired plot:

plot desired.png

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 7 replies
  • 9389 views
  • 1 like
  • 3 in conversation