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

I have patients in my data with repeated observations. "uid"=unique identifier of patients. dos=date of survey. I'd like to subset data where patients have future date of survey (2019). Below approach outputs the rows only where dos=2019 but not along with previous years of information which I need to have to investigate the source of error. 

Your help is appreciated to come up with data "want" from the code block below. Using SAS 9.4.

 

data have;
input uid dos;
cards;
1 2015
1 2016
1 2019
2 2017 
2 2018
3 2019
4 2015
4 2016
4 2017
5 2015
;

data want;
input uid dos;
cards;
1 2015
1 2016
1 2019
3 2019
;

proc sort data=have; 
by uid;
run; 
data wrong; set have;
by uid;
if dos in (2019) then output;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
proc sql;

create table want as
select * from have 
where uid in 
    (select uid from have where dos=2019);

quit;

View solution in original post

3 REPLIES 3
Reeza
Super User
proc sql;

create table want as
select * from have 
where uid in 
    (select uid from have where dos=2019);

quit;
Cruise
Ammonite | Level 13
worked out! but why? trying to visualize how SAS is calling data here
Reeza
Super User
proc sql;

create table want as
select * from have 
where uid in /*selects only IDS from this list*/ 
    (select distinct uid from have where dos=2019); *<- this creates a list of IDs where it is 2019, should add the DISTNCT word here;

quit;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 802 views
  • 0 likes
  • 2 in conversation