Can this DATA step be incorporated into the PROC SQL step so that course_numbers beginning with '08' are excluded when table stud4 is created?
proc sql;
create table stud4 as
SELECT S.*,CC.COURSE_NUMBER, CC.SECTION_NUMBER, CC.SCHOOLID as cc_schoolID, T.TEACHERNUMBER,
T.LASTFIRST as TEACHER, courses.course_name
FROM stud3b as s
left join myoracle.cc as cc
on s.ID=cc.studentid
left join myoracle.teachers as t
on cc.teacherid=t.ID
left join myoracle.COURSES as courses
on cc.COURSE_NUMBER=courses.course_number
where cc.termid ge 2800
order by s.student_number;
quit;
data stud4a;
set stud4;
if course_number in:('08') then delete;
run;
If you want the left join to work properly with a where condition on the table on the right side of the join, you must force SQL to apply the condition before operating the join, as such:
proc sql;
create table stud4 as
SELECT
S.*,
CC.COURSE_NUMBER,
CC.SECTION_NUMBER,
CC.SCHOOLID as cc_schoolID,
T.TEACHERNUMBER,
T.LASTFIRST as TEACHER,
courses.course_name
FROM
stud3b as s left join
( select *
from myoracle.cc
where
course_number net "08" and
termid ge 2800 ) as cc on s.ID=cc.studentid left join
myoracle.teachers as t on cc.teacherid=t.ID left join
myoracle.COURSES as courses on cc.COURSE_NUMBER=courses.course_number
order by s.student_number;
quit;
otherwise, the where condition is applied to the missing values generated by the join and those added records are removed (you end up with the equivalent of an inner join, not a left join)
Perhaps
proc sql;
create table stud4 as
SELECT S.*,CC.COURSE_NUMBER, CC.SECTION_NUMBER, CC.SCHOOLID as cc_schoolID, T.TEACHERNUMBER,
T.LASTFIRST as TEACHER, courses.course_name
FROM stud3b as s
left join myoracle.cc as cc
on s.ID=cc.studentid
left join myoracle.teachers as t
on cc.teacherid=t.ID
left join myoracle.COURSES as courses
on cc.COURSE_NUMBER=courses.course_number
where cc.termid ge 2800
having cc.course_number not like ('08%')
order by s.student_number;
quit;
EDITED to NOT like
sorry
or is it
where cc.termid ge 2800 and cc.course_number not like ('08%')
EDITED to NOT like
sorry
doesn't this do the opposite?
Don't know your data. I am taking a wild guess
Oops sorry
should be NOT like
Alternatively, you can use a dataset option:
create table stud4(where=(course_number~=:'08')) as
If you want the left join to work properly with a where condition on the table on the right side of the join, you must force SQL to apply the condition before operating the join, as such:
proc sql;
create table stud4 as
SELECT
S.*,
CC.COURSE_NUMBER,
CC.SECTION_NUMBER,
CC.SCHOOLID as cc_schoolID,
T.TEACHERNUMBER,
T.LASTFIRST as TEACHER,
courses.course_name
FROM
stud3b as s left join
( select *
from myoracle.cc
where
course_number net "08" and
termid ge 2800 ) as cc on s.ID=cc.studentid left join
myoracle.teachers as t on cc.teacherid=t.ID left join
myoracle.COURSES as courses on cc.COURSE_NUMBER=courses.course_number
order by s.student_number;
quit;
otherwise, the where condition is applied to the missing values generated by the join and those added records are removed (you end up with the equivalent of an inner join, not a left join)
Me nether... You made me look
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.