Hi ALL,
I have two variables called "SITE1" and "SITE2", and I wrote a format for these 2 variables;
Unfortunately when I run PROC PHREG an error on formating stoped the proc;
Error: Variable SITE2 in WORK.DATA1 does not have the same format as in the input data
How can I come across this situation???
Thanks
proc format ;
value SITE1
1 = 'A'
2 = 'B'
3 = 'C'
;
value SITE2
1= 'D'
2 = 'F'
;
proc phreg data=DATA1;
title "......";
class SITE1 SITE2/ ref=first;
model survtime*died(0)=SITE1 SITE2;
baseline covariates=DATA1 out=oversurv survival=_all_ /diradj group=SITE1;
format SITE1 SITE1.
SITE2 SITE2.;
hazardratio SITE1 / diff=ref cl=both;
run;
Error: Variable SITE2 in WORK.DATA1 does not have the same format as in the input data
what does that mean?
Error: Variable SITE2 in WORK.DATA1 does not have the same format as in the input data
Your code is referencing the same dataset twice. Once in the DATA= option and then again in the COVARIATES= option. So it probably is complaining that when it goes to read it the second time it notices that in the dataset DATA1 does the variable SITE2 does NOT have the format SITE2. attached, but the data it is reading from the DATA= option it DOES have it attached because of the FORMAT statement included in the PROC step.
What happens if you attach the format in the data set first and remove the FORMAT statement from the PROC step?
proc datasets nolist lib=work;
modify data1;
format site1 site1. site2 site2.;
run;
quit;
proc phreg data=DATA1;
title "......";
class SITE1 SITE2/ ref=first;
model survtime*died(0)=SITE1 SITE2;
baseline covariates=DATA1 out=oversurv survival=_all_ /diradj group=SITE1;
hazardratio SITE1 / diff=ref cl=both;
run;
Your formats take a numeric variable and change their appearance as specified by the format.
So the error is probably that SITE2 is a character variable, and you can't apply a format designed for a numeric variable.
You need a format designed for a character variable.
value $SITE2
'1'= 'D'
'2' = 'F'
;
Thank you!
But I'm sure of the data type of SITE2 is numeric.
To double check, I changed the format SITE2 for a character variable, then...
ERROR: The variable 'SITE2' has already been defined as numeric. The attempt to redefine the
variable type to character is ignored.
That's really weird
Error: Variable SITE2 in WORK.DATA1 does not have the same format as in the input data
Your code is referencing the same dataset twice. Once in the DATA= option and then again in the COVARIATES= option. So it probably is complaining that when it goes to read it the second time it notices that in the dataset DATA1 does the variable SITE2 does NOT have the format SITE2. attached, but the data it is reading from the DATA= option it DOES have it attached because of the FORMAT statement included in the PROC step.
What happens if you attach the format in the data set first and remove the FORMAT statement from the PROC step?
proc datasets nolist lib=work;
modify data1;
format site1 site1. site2 site2.;
run;
quit;
proc phreg data=DATA1;
title "......";
class SITE1 SITE2/ ref=first;
model survtime*died(0)=SITE1 SITE2;
baseline covariates=DATA1 out=oversurv survival=_all_ /diradj group=SITE1;
hazardratio SITE1 / diff=ref cl=both;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: