BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TANMOY05
Obsidian | Level 7
data ecg ;
	set renibus20(in=a) 
		renibus211(in=b1 where=(assess^='')) 
		renibus212(in=b2 where=(assess^=''))  
		renibus221(in=c1 where=(assess^='')) 
		renibus222(in=c2 where=(assess^='')) 
		renibus231(in=d1 where=(assess^='')) 
		renibus232(in=d2 where=(assess^='')) ;
	subject=put(input(subject_id,best.),z3.) ;
	length VISIT $20 ;
	if a then VISIT='Screening' ;
	if b1 or c1 or d1 then visit='Day 1 Predose' ;
	if b2 or c2 or d2 then visit='Day 1 Predose' ;
	VISITN=1.1*(b1 or c1 or d1)+1.2*(b2 or c2 or d2) ;
	drop _name_ _label_ subject_id ;
run ;

I am getting error as 

ERROR: WHERE clause operator requires compatible variables.
ERROR: Variable ASSESS has been defined as both character and numeric.
what to do?
even where=(not missing(assess)) is showing error Variable ASSESS has been defined as both character and numeric.
 
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

In one of your data sets in the SET statement, variable ASSESS is numeric; in another of your data sets variable ASSESS is character. You need to fix this in order to get this to work. ASSESS must always be numeric in each of your data sets; or it must always be character in each of your data sets.

--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

In one of your data sets in the SET statement, variable ASSESS is numeric; in another of your data sets variable ASSESS is character. You need to fix this in order to get this to work. ASSESS must always be numeric in each of your data sets; or it must always be character in each of your data sets.

--
Paige Miller
TANMOY05
Obsidian | Level 7
In those datasets where variable ASSESS is character , is there anyway i present it as numeric as those variable contains no observations and therefore SAS is reading it as character and those variables too are needed to create dataset ecg.
Kurt_Bremser
Super User

You need to go back to the start of your process, where the data is read into your SAS environment in the first place. Do not use proc import for this, instead use the same data step to read all files, then the datasets will have the same structure.

PaigeMiller
Diamond | Level 26

@TANMOY05 wrote:
In those datasets where variable ASSESS is character , is there anyway i present it as numeric as those variable contains no observations and therefore SAS is reading it as character and those variables too are needed to create dataset ecg.

In a data step, you rename ASSESS to something else (let's say ASSESS_C) and then create a new variable named ASSESS which is numeric and contains the numeric portion of whatever values are in ASSESS_C.

 

And also ... what @Kurt_Bremser said is good advice.

--
Paige Miller
ballardw
Super User

@TANMOY05 wrote:
data ecg ;
	set renibus20(in=a) 
		renibus211(in=b1 where=(assess^='')) 
		renibus212(in=b2 where=(assess^=''))  
		renibus221(in=c1 where=(assess^='')) 
		renibus222(in=c2 where=(assess^='')) 
		renibus231(in=d1 where=(assess^='')) 
		renibus232(in=d2 where=(assess^='')) ;
	subject=put(input(subject_id,best.),z3.) ;
	length VISIT $20 ;
	if a then VISIT='Screening' ;
	if b1 or c1 or d1 then visit='Day 1 Predose' ;
	if b2 or c2 or d2 then visit='Day 1 Predose' ;
	VISITN=1.1*(b1 or c1 or d1)+1.2*(b2 or c2 or d2) ;
	drop _name_ _label_ subject_id ;
run ;

I am getting error as 

ERROR: WHERE clause operator requires compatible variables.
ERROR: Variable ASSESS has been defined as both character and numeric.
what to do?
even where=(not missing(assess)) is showing error Variable ASSESS has been defined as both character and numeric.
 

One suspects there is a LOGIC error on this line:

if b2 or c2 or d2 then visit='Day 1 Predose' ;

That perhaps the visit value should either have a different Day or something besides "Predose". Otherwise why have a different "If' to differentiate between b1 c1 and d1.

 

You may want to consider whether visit should be formed that way. You are actually containing two pieces of informat, Day and Dose status. Which may make it much harder to look at "Predose" vs other Dose status values.

 

Another consideration if you have many of these, such that you get up to values like 'Day 10 Dose' then your sort order for visit for many purposes will be "Day 1   ", "Day 10", "Day 11" , "Day 2" or similar. So you might be better off with a numeric Day value that sorts appropriately.

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 1118 views
  • 2 likes
  • 4 in conversation