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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

 

 

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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'
;
--
Paige Miller
Claire_panda
Calcite | Level 5

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

 

 

Tom
Super User Tom
Super User

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;

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1900 views
  • 0 likes
  • 3 in conversation