BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lillymaginta
Lapis Lazuli | Level 10

 I have the following data, multiple observation per id. several s_Date, one adm_date per id,

I want to do the following: if hf=1 and the s_date is before adm_date then delete all observation for that id. 

 

 

id       s_date           hf      adm_Date         
1        1/1/2005       1       2/2/2004
1        7/7/2005       0
2        4/3/2004       0
2       2/2/2005        1       6/7/2005
2                       0
3                       0
3       4/4/2006        1     8/8/2005
3

 

1 ACCEPTED SOLUTION

Accepted Solutions
mohamed_zaki
Barite | Level 11
data have;
input id s_date ddmmyy9. hf adm_Date ddmmyy9.;
cards;
1 1/1/2005 1 2/2/2004
1 7/7/2005 0 .
2 4/3/2004 0 .
2 2/2/2005 1 6/7/2005
2 . 0 .
3 . 0 .
3 4/4/2006 1 8/8/2005
;
run;

proc sql ;
create table want as
select *
from have
where id not in (select distinct id from have where s_date < adm_date and hf=1)
;
quit;

View solution in original post

5 REPLIES 5
mohamed_zaki
Barite | Level 11

Is there will always be only one hf=1 per id?

mohamed_zaki
Barite | Level 11
data have;
input id s_date ddmmyy9. hf adm_Date ddmmyy9.;
cards;
1 1/1/2005 1 2/2/2004
1 7/7/2005 0 .
2 4/3/2004 0 .
2 2/2/2005 1 6/7/2005
2 . 0 .
3 . 0 .
3 4/4/2006 1 8/8/2005
;
run;

proc sql ;
create table want as
select *
from have
where id not in (select distinct id from have where s_date < adm_date and hf=1)
;
quit;
stat_sas
Ammonite | Level 13

proc sql;
create table want as
select * from have
group by id
having sum(case when s_date<adm_date and hf=1 then 1 else 0 end)=0;
quit;

lillymaginta
Lapis Lazuli | Level 10
Thank you Mohamed asnd stat_sas both codes worked and produced the same results. I appreciate it

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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