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

I've been asked to re-post my question.

 

First of all, thank you to all of community who helped me on my last post.

 

Current Question:

I've asked to work with proc gplot in an existing program.  Once I have made the necessary changes and run my code I get a plot with a regression line that is not one continuous line.

 

My code is as follows:

 

 

symbol1 v=circle i=none c=BLACK h=2;
symbol2 v=none l=1 i=join c=BLACK h=3;
symbol3 v=square i = none c=BLACK h=3;
symbol4 v=star i = none c=BLACK h=3;

*goptions ftext=ARIAL;
axis1 logbase=10 logstyle=expand minor=(h=0.5) label=(h=2.5 "Cycle");
axis2 logbase=10 logstyle=expand minor=(h=0.5) label=(h=2.5 angle=90 "&l_pparm");
legend1 value=('Individual' 'Linear Regression' 'Geometric Mean' 'Median') label=(' ');

proc gplot data=pk1 annotate=anno;
	plot pkpraw*cpevent1=1
		yp*cpevent1=2
		_geomean*cpevent1=3
		z_median*cpevent1=4
		/overlay skipmiss vaxis=axis2 haxis=axis1 hzero vzero legend=legend1 noframe;
	format pkpraw pred _geomean z_median 8.;
run;

quit;

 

Data Used:

 


data SAMPLE;
	infile datalines dsd truncover;
	input PKPRAW:32. cpevent1:$200. cpevent2:32. pred:32. z_median:32. _geomean:32. yp:32.;
	label PKPRAW="PK Parameter Value" pred="Predicted Value of y" z_median="PK Parameter Value";
	datalines4;
11,C2D1,2,3.655622292,61.2,58.272469199,38.691591091
25.2,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
27.1,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
27.3,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
29.8,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
30.5,C2D1,2,3.655622292,61.2,58.272469199,38.691591091
34.9,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
39,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
39.2,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
42.4,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
44.3,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
45.8,C2D1,2,3.655622292,61.2,58.272469199,38.691591091
47.6,C2D1,2,3.655622292,61.2,58.272469199,38.691591091
47.7,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
48,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
49,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
53.6,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
56,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
58.3,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
59.6,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
60.6,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
61.8,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
62.5,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
65,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
66.2,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
67.2,C2D1,2,3.655622292,61.2,58.272469199,38.691591091
72.8,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
74.3,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
76.6,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
79.6,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
81.4,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
81.8,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
81.9,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
84.4,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
89.2,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
93,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
94.9,C2D1,2,3.655622292,61.2,58.272469199,38.691591091
114,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
117,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
121,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
135,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
168,C2D1,2,4.12454122,61.2,58.272469199,61.839432047
5.93,C3D1,3,3.655622292,58.1,53.458339518,38.691591091
14.3,C3D1,3,3.655622292,58.1,53.458339518,38.691591091
24.2,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
29.9,C3D1,3,3.655622292,58.1,53.458339518,38.691591091
39.6,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
43.9,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
44.7,C3D1,3,3.655622292,58.1,53.458339518,38.691591091
44.8,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
47.4,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
47.5,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
51,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
52.4,C3D1,3,3.655622292,58.1,53.458339518,38.691591091
52.9,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
55.3,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
55.5,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
58.1,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
61.7,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
63.1,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
64.8,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
67.9,C3D1,3,3.655622292,58.1,53.458339518,38.691591091
69.4,C3D1,3,3.655622292,58.1,53.458339518,38.691591091
71.6,C3D1,3,3.655622292,58.1,53.458339518,38.691591091
79.2,C3D1,3,3.655622292,58.1,53.458339518,38.691591091
80.1,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
80.7,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
81.3,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
82,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
83.2,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
87.3,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
108,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
134,C3D1,3,4.12454122,58.1,53.458339518,61.839432047
6.91,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
11.8,C4D1,4,3.655622292,61.9,53.37077009,38.691591091
19.4,C4D1,4,3.655622292,61.9,53.37077009,38.691591091
27.4,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
28.6,C4D1,4,3.655622292,61.9,53.37077009,38.691591091
32.8,C4D1,4,3.655622292,61.9,53.37077009,38.691591091
34.7,C4D1,4,3.655622292,61.9,53.37077009,38.691591091
38.2,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
41.9,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
43.1,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
44.7,C4D1,4,3.655622292,61.9,53.37077009,38.691591091
45.9,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
49.5,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
59.2,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
60.5,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
61.7,C4D1,4,3.655622292,61.9,53.37077009,38.691591091
62.1,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
65.3,C4D1,4,3.655622292,61.9,53.37077009,38.691591091
66.7,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
67.2,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
68.4,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
70,C4D1,4,3.655622292,61.9,53.37077009,38.691591091
70.5,C4D1,4,3.655622292,61.9,53.37077009,38.691591091
72.6,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
75.8,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
83,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
95.6,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
98.3,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
103,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
113,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
165,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
170,C4D1,4,4.12454122,61.9,53.37077009,61.839432047
;;;;

 

The output is attached.

 

Thank you in advance.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

In your symbol2 statement, you'll need to use i=rl (interpol = regression line) rather than i=join (simple line).

 

And in order for the rl interpolation to work, I believe your x-axis has to be numeric, rather than character. Therefore I create a cpevent1_num variable in a data step...

 

data pk1; set pk1;
if cpevent1='C2D1' then cpevent1_num=1;
if cpevent1='C3D1' then cpevent1_num=2;
if cpevent1='C4D1' then cpevent1_num=3;
run;

symbol1 v=circle i=none c=BLACK h=2;
symbol2 v=none l=1 i=rl c=black;
symbol3 v=square i = none c=BLACK h=3;
symbol4 v=star i = none c=BLACK h=3;

axis1 minor=none label=(h=2.5 "Cycle");
axis2 logbase=10 logstyle=expand minor=(h=0.5) label=(h=2.5 angle=90 "&l_pparm");
legend1 value=('Individual' 'Linear Regression' 'Geometric Mean' 'Median') label=(' ');

proc gplot data=pk1 /*annotate=anno*/;
plot pkpraw*cpevent1_num=1
yp*cpevent1_num=2
_geomean*cpevent1_num=3
z_median*cpevent1_num=4
/overlay
skipmiss vaxis=axis2 haxis=axis1 hzero vzero legend=legend1 noframe;
format pkpraw pred _geomean z_median 8.;
run;

 

This produces a graph with a straight regression line:

 

reg1.png

 

 

If you want the numeric 1, 2, and 3 to show up as text values, you can use a user-defined-format, such as ...

 

proc format;
value cpfmt
1 = 'C2D1'
2 = 'C3D1'
3 = 'C4D1'
;
run;
data pk1; set pk1;
format cpevent1_num cpfmt.;
if cpevent1='C2D1' then cpevent1_num=1;
if cpevent1='C3D1' then cpevent1_num=2;
if cpevent1='C4D1' then cpevent1_num=3;
run;

 

reg2.png

 

View solution in original post

9 REPLIES 9
DanH_sas
SAS Super FREQ

Your X variable is a character variable, yet you're trying to create a regression plot with it. Was that your intent?

cjkim1030
Calcite | Level 5

I wasn't the one to write the original code and I have little experience with figures.  Could this be a reason for the odd regression line?

ballardw
Super User

@cjkim1030 wrote:

I wasn't the one to write the original code and I have little experience with figures.  Could this be a reason for the odd regression line?


Is the example "data" the output from a regression procedure?

If not, what do you think is creating a "regression" line.

A symbol statement with the INTERPOL=R or I=R option will create regressions. The value of R can be modified with L Q or C to do linear, quadratic or cubic regressions with options to display confidence limits of mean or individual predicted values with confidence levels from 50% to 99% (defaults to 95%). So a symbol statement might look like Symbol2 I=RLCLM95;

HOWEVER the x-axis variable would have to be numeric to work at all. Since your x variable is character GPLOT can't do a "regression" with the value.

cjkim1030
Calcite | Level 5

So, I'm scrolling up in the code and found the following:

 

ods output ParameterEstimates=est FitStatistics=fit anova=anova;
proc reg data =pk;
model y=x/clb alpha=.1;
output out=reg p=pred;
run;
quit;

ods output close;
data fit1(keep=ord label2 cvalue2);
set fit;
where label2='R-Square';
ord=2;
run;

data cl1(keep=ord estimate lowercl uppercl rename=(estimate=b))
cl2(keep=ord estimate rename=(estimate=a));
set est;

if upcase(variable)='X' then do;
ord=1;
output cl1;
end;
else do;
ord=1;
output cl2;
end;
run;

data cl;
merge cl1 cl2;
by ord;
run;

data stat;
set cl fit1;
run;

proc sort data=reg;
by cpevent1 subjid;
run;

 

Does the proc reg, creating the regression data?

 

The dataset reg is merged in with the other stats to create the pk1.

ballardw
Super User

@cjkim1030 wrote:

So, I'm scrolling up in the code and found the following:

 Does the proc reg, creating the regression data?

The dataset reg is merged in with the other stats to create the pk1.


Proc Reg is creating 4 separate output data sets, EST which contains parameter estimates: the intercept and slope of X, FIT which has parameter estimates; Anova which contains analysis of variance bits and Reg which has the X and Y values plus the predicted Y values.

 

From the proc gplot code you have shown I am not sure what the intent was as your code references several variables without indicating where they came from or represent: cpevent1 , yp (I might guess is a predicted Y but that isn't the name it would have from Proc reg shown), _geomean and z_median.

This code:

proc sort data=reg;
by cpevent1 subjid;
run;

implies the cpevent1 and subjid are in the REG data set but as created by the Proc reg code shown it should only have x, y and pred variables.

proc reg data =pk;
model y=x/clb alpha=.1;
output out=reg p=pred;
run;
quit;

the output data set has only 1) model variables ( Y and X) and 2)requested values, in this case PRED for the predicted Y value. So that data set REG appears not to be the one from the proc reg output.

 

 

I would expect to see a plot of Pred*X as the regression values plot. With no idea where or why the cpeven1 variable comes from it is extremely hard to guess why anything related to it is important.

 

You are learning why there is a programming feature called COMMENTS. To place text in a program to describe what is going on or in many cases more important why a step is done.

Reeza
Super User
cjkim1030
Calcite | Level 5

I wish that was the case, but it's for work.

GraphGuy
Meteorite | Level 14

In your symbol2 statement, you'll need to use i=rl (interpol = regression line) rather than i=join (simple line).

 

And in order for the rl interpolation to work, I believe your x-axis has to be numeric, rather than character. Therefore I create a cpevent1_num variable in a data step...

 

data pk1; set pk1;
if cpevent1='C2D1' then cpevent1_num=1;
if cpevent1='C3D1' then cpevent1_num=2;
if cpevent1='C4D1' then cpevent1_num=3;
run;

symbol1 v=circle i=none c=BLACK h=2;
symbol2 v=none l=1 i=rl c=black;
symbol3 v=square i = none c=BLACK h=3;
symbol4 v=star i = none c=BLACK h=3;

axis1 minor=none label=(h=2.5 "Cycle");
axis2 logbase=10 logstyle=expand minor=(h=0.5) label=(h=2.5 angle=90 "&l_pparm");
legend1 value=('Individual' 'Linear Regression' 'Geometric Mean' 'Median') label=(' ');

proc gplot data=pk1 /*annotate=anno*/;
plot pkpraw*cpevent1_num=1
yp*cpevent1_num=2
_geomean*cpevent1_num=3
z_median*cpevent1_num=4
/overlay
skipmiss vaxis=axis2 haxis=axis1 hzero vzero legend=legend1 noframe;
format pkpraw pred _geomean z_median 8.;
run;

 

This produces a graph with a straight regression line:

 

reg1.png

 

 

If you want the numeric 1, 2, and 3 to show up as text values, you can use a user-defined-format, such as ...

 

proc format;
value cpfmt
1 = 'C2D1'
2 = 'C3D1'
3 = 'C4D1'
;
run;
data pk1; set pk1;
format cpevent1_num cpfmt.;
if cpevent1='C2D1' then cpevent1_num=1;
if cpevent1='C3D1' then cpevent1_num=2;
if cpevent1='C4D1' then cpevent1_num=3;
run;

 

reg2.png

 

cjkim1030
Calcite | Level 5

I was able to figure this out based on other comments and yours verifies it.

 

Thanks.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 9 replies
  • 2199 views
  • 2 likes
  • 5 in conversation