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

Here is my code:

proc sql;

create table reenroll_statecourses_teacher as select

c.*,r.* from statecourses_teacher as c left join join1 as r 

on c.studentID=r.studentID and c.crs_schoolid=r.schoolid and c.termid lt 0 and (c.dateleft=r.exitdate or c.dateleft=r.exitdate+1)

order by studentID;

quit;

I believe the part in bold "and c.termid lt 0" is not correct because the matching is not what I'm wanting.  I only want observations from the data set "statecourses_teacher" WHERE the termid is negative but I get matches where termid is both positive and negative.  I checked and termid is a numeric value.

I appreciate any  help.

Gregg

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

In a left join, every record from the left table is included in the result, even when the on condition is not met. Move the condition to a where clause :

proc sql;

create table reenroll_statecourses_teacher as select

c.*,r.* from statecourses_teacher as c left join join1 as r

on c.studentID=r.studentID and c.crs_schoolid=r.schoolid and (c.dateleft=r.exitdate or c.dateleft=r.exitdate+1)

where c.termid lt 0

order by studentID;

quit;

PG

PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

In a left join, every record from the left table is included in the result, even when the on condition is not met. Move the condition to a where clause :

proc sql;

create table reenroll_statecourses_teacher as select

c.*,r.* from statecourses_teacher as c left join join1 as r

on c.studentID=r.studentID and c.crs_schoolid=r.schoolid and (c.dateleft=r.exitdate or c.dateleft=r.exitdate+1)

where c.termid lt 0

order by studentID;

quit;

PG

PG
GreggB
Pyrite | Level 9

Thank you very much.  I am getting the expected results now.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 2 replies
  • 882 views
  • 0 likes
  • 2 in conversation