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

Hello,

  I have two variables  pref_hat and BrewingTime (2 mins, 4 mins, 6mins and 8mins).   I used the following procedure:  

proc sgplot data = conjoint;
scatter y=pref_hat x=BrewingTime;
run;

    How can I connect the mean of pref_hat in each of BrewingTime in the scatter plot below?

Bests,

Golf

Golf_0-1595045097283.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @Golf,

 

I would combine the scatter plot with a line plot using precomputed mean values:

/* Create test data for demonstration */

data conjoint(drop=b);
length BrewingTime $8;
do _n_=1 to 9;
  pref_hat=0.3+0.4*rannor(1425674559);
  do b=2 to 8 by 2;
    pref_hat=pref_hat+b/18-b**2/65;
    BrewingTime=catx(' ',b,'Mins');
    output;
  end;
end;
run;

/* Compute mean values */

proc summary data=conjoint nway;
class BrewingTime;
var pref_hat;
output out=stats mean=mean_pref_hat;
run;

/* Append mean values to detail data */

data want;
set conjoint stats;
run;

/* Combine scatter plot with line plot */

proc sgplot data=want;
scatter y=pref_hat      x=BrewingTime;
series  y=mean_pref_hat x=BrewingTime / markers markerattrs=(symbol=X);
run;

Result:

overlay_plot.png

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hello @Golf,

 

I would combine the scatter plot with a line plot using precomputed mean values:

/* Create test data for demonstration */

data conjoint(drop=b);
length BrewingTime $8;
do _n_=1 to 9;
  pref_hat=0.3+0.4*rannor(1425674559);
  do b=2 to 8 by 2;
    pref_hat=pref_hat+b/18-b**2/65;
    BrewingTime=catx(' ',b,'Mins');
    output;
  end;
end;
run;

/* Compute mean values */

proc summary data=conjoint nway;
class BrewingTime;
var pref_hat;
output out=stats mean=mean_pref_hat;
run;

/* Append mean values to detail data */

data want;
set conjoint stats;
run;

/* Combine scatter plot with line plot */

proc sgplot data=want;
scatter y=pref_hat      x=BrewingTime;
series  y=mean_pref_hat x=BrewingTime / markers markerattrs=(symbol=X);
run;

Result:

overlay_plot.png

Golf
Pyrite | Level 9
Hello FreelanceReinhard AMETHYS,
Thank You so much for very cool codes.
Bests,
Golf.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 3163 views
  • 3 likes
  • 2 in conversation