BookmarkSubscribeRSS Feed
Mogamo_Khushua
Calcite | Level 5

I am combine two data sets based on a patient's date of surgery falling between +/- 1 month of when a patient completed their survey.

dataset abc has  variables lastname, firstname, dob, and survey_completed 

dataset xyz has variables last, first, date_birth, and date_surgery

Here's my code:

proc sql; 
create table want as
select distinct t1.*,
intnx('month', t1.Survey_Completed, -1, 'sameday') as first_survey format=date9.,
intnx('month', t1.survey_completed, 1, 'sameday') as last_survey format=date9.,
t2.last,
t2.first,
t2.date_birth,
t2.date_surgery as DOS format date9.
from abc as t1
left join xyz as t2
on t1.dob=t2.date_birth and t1.last_name=t2.last and t1.first_name=t2.first
where DOS between first_survey and last_survey
order by last_name;
quit;

 

with the above code I am getting the following error message:

ERROR: Expression using BETWEEN has components that are of different data types.
ERROR: The following columns were not found in the contributing tables: first_survey, last_survey.

 

What am i doing wrong? 

4 REPLIES 4
Reeza
Super User
t2.date_surgery as DOS format date9.  <- missing the equal sign here

What's the type/format on date_surgery before the query? I suspect it's a character variable and you'd need to convert it to a numeric variable and a SAS date first. 

Mogamo_Khushua
Calcite | Level 5

type is numeric and format is date9.

PGStats
Opal | Level 21

You must use the calculated keyword when referring to a calculated column.

 

where DOS between calculated first_survey and calculated last_survey
PG
Mogamo_Khushua
Calcite | Level 5

It works after using 'calculated'. 

 

Thank you very much. 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 680 views
  • 0 likes
  • 3 in conversation