BookmarkSubscribeRSS Feed
Paako
Calcite | Level 5

Hi, I'm new to SAS and having a trouble with drawing a cubic spline curve. I'm using SAS 9.4.

I analyzed my data with the multivariable-adjusted Cox proportional hazard regression model. The program is like this;

 

proc phreg data=data1;

model personyears*case(0)=mets sex age DM/rl;

run;

 

"mets" means METs which is used to estimate physical activity level. Sex, age, DM are covariates.

I would like to draw a cubic spline curve. The y-axis is hazard ratio and the x-axis is METs. The hazard ratio is 1 when METs is 0.

 

I'm wondering if "proc icphreg" may be an applicable program, but I cannot find the program which fits my request. Could you tell me the program to solve my question? Thank you.

13 REPLIES 13
Reeza
Super User

Did you see this example?

 

https://documentation.sas.com/?docsetId=statug&docsetVersion=15.1&docsetTarget=statug_icphreg_exampl...

 


@Paako wrote:

Hi, I'm new to SAS and having a trouble with drawing a cubic spline curve. I'm using SAS 9.4.

I analyzed my data with the multivariable-adjusted Cox proportional hazard regression model. The program is like this;

 

proc phreg data=data1;

model personyears*case(0)=mets sex age DM/rl;

run;

 

"mets" means METs which is used to estimate physical activity level. Sex, age, DM are covariates.

I would like to draw a cubic spline curve. The y-axis is hazard ratio and the x-axis is METs. The hazard ratio is 1 when METs is 0.

 

I'm wondering if "proc icphreg" may be an applicable program, but I cannot find the program which fits my request. Could you tell me the program to solve my question? Thank you.


 

Paako
Calcite | Level 5

Hi, Reeza, thank you for the reply.

I had already checked the page you mentioned and tried first this program;

 

proc icphreg data=data1;

model personyears*case(0)=mets sex age DM/basehaz=splines;
hazardratio activemets;
run;

 

but the log says there is a syntax error and it doesn't work. Do you have any idea?

Reeza
Super User
Post your log. But given that you haven't included activemets as a variable but do have it in your hazardratio statement I suspect that alone would cause an error.
Paako
Calcite | Level 5

Thank you for the reply. I made a mistake when I posted my program. I wrote the program as an example, and this is my actual program;

 

proc icphreg data=jalskaiseki10;
model gyear*FIRST_HASSHO(0)=activemets sexa age DMC/basehaz=splines;
hazardratio activemets;
run;

 

but the log says there is a syntax error again.

here is the log;

 

159  proc icphreg data=jalskaiseki10;
160  model gyear*FIRST_HASSHO(0)=activemets sexa age DMC/basehaz=splines;
           -----
           79
           76
ERROR 79-322: (designate
ERROR 76-322: there is a syntax error
161  run;

 

My sas is not in English, so " designate" and "there is a syntax error" is my translation.

In the program, "hazardratio" is red-letter allthough "proc icphreg", "model" and "run" is blue-letter. I suspect there is a syntax error in 

"hazardratio activemets;", but I cannot find the problem.

 

 

Reeza
Super User

What version of SAS are you using? I'm guessing ICPHREG is a newer proc and you don't have a version that supports it. 

 

Check this via, and see what the SAS/STAT version is. 

 

proc product_status;run;

@Paako wrote:

Thank you for the reply. I made a mistake when I posted my program. I wrote the program as an example, and this is my actual program;

 

proc icphreg data=jalskaiseki10;
model gyear*FIRST_HASSHO(0)=activemets sexa age DMC/basehaz=splines;
hazardratio activemets;
run;

 

but the log says there is a syntax error again.

here is the log;

 

159  proc icphreg data=jalskaiseki10;
160  model gyear*FIRST_HASSHO(0)=activemets sexa age DMC/basehaz=splines;
           -----
           79
           76
ERROR 79-322: (designate
ERROR 76-322: there is a syntax error
161  run;

 

My sas is not in English, so " designate" and "there is a syntax error" is my translation.

In the program, "hazardratio" is red-letter allthough "proc icphreg", "model" and "run" is blue-letter. I suspect there is a syntax error in 

"hazardratio activemets;", but I cannot find the problem.

 

 


 

Paako
Calcite | Level 5

The log says;

 

For SAS/STAT ...
   Custom version information: 13.2
For SAS/GRAPH ...
   Custom version information: 9.4_M2
For High Performance Suite ...
   Custom version information: 2.2_M3
   Image version information: 9.04.01M0P042215

 

I think my version is 13.2.

Doesn't it have a way to draw a spline curve? Or another syntax?

Reeza
Super User
ICPHREG is available in 13.2 so that's not the issue. You are definitely on an older version though, 9.4M2 is from 2014. Anyways, please post your full code and log, since we can't really help with what you've posted so far. The error could be in your MODEL statement or somewhere else.
Paako
Calcite | Level 5

Here is my sas code. In the code, EGFRC=1 means eGFR<50. If eGFR>=50. EGFRC=0;

data jalshassho;
set base4;
if (area=88 and  2005<=eyear) or (area=23 and  2004<=eyear) ;
IF EGFRC=1 THEN ; ELSE DELETE;
run;
proc sort data = jalshassho;
by REGI eyear;
run ;

DATA  jalshassho1;
SET jalshassho;
BY REGI eyear ;
if FIRST.REGI=1 THEN  FIRST_HASSHO=1;
IF FIRST_HASSHO=1 THEN; ELSE DELETE;

KEEP REGI KENKAID eyear  area EMONTH EDAY CRT EGFR_E EGFRC FIRST_HASSHO;  

RENAME
 eyear = EYEAR_CASE
 EMONTH = EMONTH_CASE
 EDAY = EDATE_CASE
 CRT = CRT_CASE
 EGFR_E = EGFR_CASE
 EGFRC = EGFRC_CASE;
run;
proc sort data=jalshassho1;
by EYEAR_CASE  area;
run;


DATA  jalslast;
SET base4;
BY REGI eyear ;
if LAST.REGI=1 THEN  LAST_NENDO=1;
IF LAST_NENDO=1 THEN; ELSE DELETE;

KEEP REGI KENKAID eyear  area EMONTH EDAY CRT EGFR_E EGFRC LAST_NENDO;  

RENAME
 eyear = EYEAR_LAST
 EMONTH = EMONTH_LAST
 EDAY = EDATE_LAST
 CRT = CRT_LAST
 EGFR_E = EGFR_LAST
 EGFRC = EGFRC_LAST ;
run;

data jalsbase0;
set base4;
activemets=sum(mets_shigoto_d,mets_hoko_d,mets_kaji_d,mets_undo_d,mets_yoka_d);
run;
data jalsbase;
set jalsbase0;
if activemets="." then delete; run;
proc sort data=jalsbase;
by regi;
run;
proc sort data=jalshassho1;
by regi;
run;
proc sort data=jalslast;
by regi;
run;


DATA jalskaiseki ;
MERGE
 jalsbase
 jalslast
 jalshassho1;
by REGI ;
run;
data jalskaiseki1;
set jalskaiseki;
GYEAR = (MDY(EMONTH_LAST,EDATE_LAST,EYEAR_LAST)-MDY(EMONTH, EDAY, eyear))/365.25 ;

IF FIRST_HASSHO=1
 then GYEAR = (MDY(EMONTH_CASE, EDATE_CASE, EYEAR_CASE)-MDY(EMONTH, EDAY, eyear))/365.25 ;

IF GYEAR=.    THEN delete;
IF  GYEAR=0   THEN delete;
IF GYEAR<0           THEN delete;
IF FIRST_HASSHO=.  THEN FIRST_HASSHO=0;

IF  GYEAR=0 and FIRST_HASSHO=0  THEN delete;;
run; 


data jalskaiseki2;
set jalskaiseki1;


DMC=.;
 IF GLU>0 or HBA1CNGSP>0 or HBA1CJDS>0  THEN DMC=0;
 IF FSTIME<8  AND  GLU >=200   THEN DMC=1;
 IF GLU=. and HBA1CNGSP >=6.5  THEN DMC=1;
 IF GLU=. and HBA1CJDS >=6.1  THEN DMC=1;
 IF 8<=FSTIME<24 AND GLU >=126    THEN DMC=1;
run; 

data jalskaiseki3;
set jalskaiseki2;
 del = 0;
 
   if CHOL = .   then del=1;
    if TG   = .   then del=1;
 if CRT = .  then del=1;
 
 IF GYEAR=.   then del=1;
 if sex =.   then del=1;
 if AGE =.   then del=1;
 if HT =.   then del=1;
 if WT =.   then del=1;
 if CRT =.  then del=1;

if eGFRC=1  then del=2;

run;


data jalskaiseki4;
set jalskaiseki3;
if del=1 then delete;
if del=2 then delete;

RUN;

proc sort data =  jalskaiseki4 ; by sex area;run;
data jalskaiseki5;
set jalskaiseki4;
if activemets="." then delete; run;
data jalskaiseki6;
set jalskaiseki5;
areas=.;
if area=88 then areas=0;
if area=23 then areas=1;
sexa=.;
if sex=1 then sexa=0; /*male*/
if sex=2 then sexa=1; /*female*/
run;

/*spline curve*/
proc icphreg data=jalskaiseki6;
model gyear*FIRST_HASSHO(0)=activemets sexa age DMC/basehaz=splines;
hazardratio activemets;
run;

 

******************************************

And here is the log;

 

 

274  data jalshassho;
275  set base4;
276  if (area=88 and  2005<=eyear) or (area=23 and  2004<=eyear) ;
277  IF EGFRC=1 THEN ; ELSE DELETE;
278  run;

NOTE: dataset WORK.BASE4 is 88814 observations

NOTE: dataset WORK.JALSHASSHO is 5915observations, 746 variables

279  proc sort data = jalshassho;
280  by REGI eyear;
281  run ;

NOTE: dataset WORK.JALSHASSHO is 5915 observations

NOTE: dataset WORK.JALSHASSHO is 5915observations, 746 variables


282
283  DATA  jalshassho1;
284  SET jalshassho;
285  BY REGI eyear ;
286  if FIRST.REGI=1 THEN  FIRST_HASSHO=1;
287  IF FIRST_HASSHO=1 THEN; ELSE DELETE;
288
289  KEEP REGI KENKAID eyear  area EMONTH EDAY CRT EGFR_E EGFRC FIRST_HASSHO;
290
291  RENAME
292      eyear = EYEAR_CASE
293      EMONTH = EMONTH_CASE
294      EDAY = EDATE_CASE
295      CRT = CRT_CASE
296      EGFR_E = EGFR_CASE
297      EGFRC = EGFRC_CASE;
298  run;

NOTE: dataset WORK.JALSHASSHO is 5915 observations

NOTE: dataset WORK.JALSHASSHO1 is 1595observations, 10 variables


299  proc sort data=jalshassho1;
300  by EYEAR_CASE  area;
301  run;

NOTE: dataset WORK.JALSHASSHO1 is 1595 observations

NOTE: dataset WORK.JALSHASSHO1 is 1595observations, 10 variables


302
303
304  DATA  jalslast;
305  SET base4;
306  BY REGI eyear ;
307  if LAST.REGI=1 THEN  LAST_NENDO=1;
308  IF LAST_NENDO=1 THEN; ELSE DELETE;
309
310  KEEP REGI KENKAID eyear  area EMONTH EDAY CRT EGFR_E EGFRC LAST_NENDO;
311
312  RENAME
313      eyear = EYEAR_LAST
314      EMONTH = EMONTH_LAST
315      EDAY = EDATE_LAST
316      CRT = CRT_LAST
317      EGFR_E = EGFR_LAST
318      EGFRC = EGFRC_LAST ;
319  run;

NOTE: dataset WORK.BASE4 is 88814 observations

NOTE: dataset WORK.JALSLAST is 15893observations, 10 variables


320
321  data jalsbase0;
322  set base4;
323  activemets=sum(mets_shigoto_d,mets_hoko_d,mets_kaji_d,mets_undo_d,mets_yoka_d);
324  run;

NOTE: dataset WORK.BASE4 is 88814 observations

NOTE: dataset JALSBASE0 is 88814observations, 746 variables


325  data jalsbase;
326  set jalsbase0;
327  if activemets="." then delete; run;

NOTE: dataset WORK.JALSBASE0 is 88814 observations

NOTE: dataset WORK.JALSBASE is 3216observations, 746 variables


328  proc sort data=jalsbase;
329  by regi;
330  run;

NOTE: dataset WORK.JALSBASE is 3216 observations

NOTE: dataset WORK.JALSBASE is 3216observations, 746 variables


331  proc sort data=jalshassho1;
332  by regi;
333  run;

NOTE: dataset JALSHASSHO1 is 1595 observations

NOTE: dataset WORK.JALSHASSHO1 is 1595observations, 10 variables


334  proc sort data=jalslast;
335  by regi;
336  run;

NOTE: dataset WORK.JALSLAST is 15893 observations

NOTE: dataset WORK.JALSLAST is 15893observations, 10 variables
337
338
339  DATA jalskaiseki ;
340  MERGE
341      jalsbase
342      jalslast
343      jalshassho1;
344  by REGI ;
345  run;

NOTE: dataset WORK.JALSBASE is 3216 observations

NOTE: dataset WORK.JALSLAST is 15893observations

NOTE: dataset WORK.JALSHASSHO1 is 1595 observations

NOTE: dataset WORK.JALSKAISEKI is 15894 observations, 761 variables


346  data jalskaiseki1;
347  set jalskaiseki;
348  GYEAR = (MDY(EMONTH_LAST,EDATE_LAST,EYEAR_LAST)-MDY(EMONTH, EDAY, eyear))/365.25 ;
349
350  IF FIRST_HASSHO=1
351      then GYEAR = (MDY(EMONTH_CASE, EDATE_CASE, EYEAR_CASE)-MDY(EMONTH, EDAY, eyear))/365.25
351!  ;
352
353  IF GYEAR=.          THEN delete;
354  IF  GYEAR=0         THEN delete;
355  IF GYEAR<0           THEN delete;
356  IF FIRST_HASSHO=.  THEN FIRST_HASSHO=0;
357
358  IF  GYEAR=0 and FIRST_HASSHO=0  THEN delete;;
359  run;

NOTE: dataset WORK.JALSKAISEKI is 15894 observations

NOTE: dataset WORK.JALSKAISEKI is 3025 observations, 762 variables


360
361
362  data jalskaiseki2;
363  set jalskaiseki1;
364
365
366  DMC=.;
367      IF GLU>0 or HBA1CNGSP>0 or HBA1CJDS>0  THEN DMC=0;
368      IF FSTIME<8     AND     GLU >=200           THEN DMC=1;
369      IF GLU=. and HBA1CNGSP >=6.5    THEN DMC=1;
370      IF GLU=. and HBA1CJDS >=6.1     THEN DMC=1;
371      IF 8<=FSTIME<24 AND GLU >=126               THEN DMC=1;
372  run;

NOTE: dataset WORK.JALSKAISEKI1 is 3025 observations

NOTE: dataset WORK.JALSKAISEKI2 is 3025observations, 763 variables


373
374  data jalskaiseki3;
375  set jalskaiseki2;
376   del = 0;
377
378      if CHOL = .         then del=1;
379      if TG   = .         then del=1;
380      if CRT = .      then del=1;
381
382      IF GYEAR=.          then del=1;
383      if sex =.           then del=1;
384      if AGE  =.          then del=1;
385      if HT   =.          then del=1;
386      if WT   =.          then del=1;
387      if CRT  =.      then del=1;
388
389  if eGFRC=1  then del=2;
390
391  run;

NOTE: dataset WORK.JALSKAISEKI2 is 3025 observations

NOTE: dataset WORK.JALSKAISEKI3 is 3025 observations, 764 variables


392
393
394  data jalskaiseki4;
395  set jalskaiseki3;
396  if del=1    then delete;
397  if del=2    then delete;
398
399  RUN;

 

NOTE: dataset WORK.JALSKAISEKI2 is 3025 observations

NOTE: dataset WORK.JALSKAISEKI4 is 2873observations, 764 variables


400
401  proc sort data =  jalskaiseki4 ; by sex area;run;

 

NOTE: dataset WORK.JALSKAISEKI4 is 2873 observations

NOTE: dataset WORK.JALSKAISEKI4 is 2873 observations, 764 variables


402  data jalskaiseki5;
403  set jalskaiseki4;
404  if activemets="." then delete; run;

NOTE: dataset WORK.JALSKAISEKI4 is 2873 observations

NOTE: dataset WORK.JALSKAISEKI5 is 2873 observations, 764 variables


405  data jalskaiseki6;
406  set jalskaiseki5;
407  areas=.;
408  if area=88 then areas=0;
409  if area=23 then areas=1;
410  sexa=.;
411  if sex=1 then sexa=0; /*male*/
412  if sex=2 then sexa=1; /*female*/
413  run;

NOTE: dataset WORK.JALSKAISEKI5 is 2873 observations

NOTE: dataset WORK.JALSKAISEKI6 is 2873 observations, 766 variables


414
415  /*spline curve*/
NOTE: there is an error

416  proc icphreg data=jalskaiseki6;
417  model gyear*FIRST_HASSHO(0)=activemets sexa age DMC/basehaz=splines;
           -----
           79
           76
ERROR 79-322: designate (
ERROR 76-322: there is a syntax error. We ignored the statement.

418  hazardratio activemets;
419  run;

 *****************************

 

The comment in the log is my translation. Sorry it's long. Could you tell me what is the problem?

 

Paako
Calcite | Level 5

I got the result such as "Analysis of Maximum Likelihood Parameter Estimates".
The log didn't tell any error. Now I have 2 questions. The first one is how I can get the spline curve
by running the demo. The second one is why my code doesn't work.

Reeza
Super User
Check the log, is there a comment about ODS Graphics being off? Make sure to turn it on first:

ods graphics on;
Paako
Calcite | Level 5

I'm sorry for the late reply. Thank you for your advice. I'll try it.

ballardw
Super User

@Paako wrote:

Hi, Reeza, thank you for the reply.

I had already checked the page you mentioned and tried first this program;

 

proc icphreg data=data1;

model personyears*case(0)=mets sex age DM/basehaz=splines;
hazardratio activemets;
run;

 

but the log says there is a syntax error and it doesn't work. Do you have any idea?


From the documentation on the HAZARDRATIO statement in ICPHREG:

The HAZARDRATIO statement enables you to request hazard ratios for any variable in the model at customized settings.

which agrees with @Reeza's diagnostic statement. If the variable isn't on the model statement it should not be on the Hazardratio.

 

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!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 13 replies
  • 3798 views
  • 2 likes
  • 3 in conversation