BookmarkSubscribeRSS Feed
miss2223
Fluorite | Level 6

Hi 

I have got two questions, below is my data code. 

data input;
input Account Name$ birthday: ddmmyy10. startdate: ddmmyy10. enddate: ddmmyy10. service_req;

format birthday: ddmmyy10. startdate: ddmmyy10. enddate: ddmmyy10.;
datalines;
1232 Ryan 01/01/1990 07/04/2017 01/03/2022 9356
1232 Ryan 01/01/1990 02/03/2022 27/08/2022 9667
1440 Chris 13/12/1987 11/03/2019 19/03/2022 5112
1440 Chris 11/12/1987 01/04/2022 30/12/9999 7891
1211 May 05/04/1998 13/09/2017 11/08/2022 1209
1265 Sandy 10/12/1988 12/08/2022 01/10/2022 1287
;

 

It will be great if someone can help me out, as I'm new to SAS. Please break down to one code per question instead of combine the code to answer both question, if its possible. 

1. Typo on Chris's birthday, account 1440 for Chris, one entry of the birthday is 13/12/1987, the other one is 11/12/1987. We believe the latest service request provides the correct date of birth

AccountNamebirthday
1232Ryan1/01/1990
1440Chris11/12/1987
1211May5/04/1998
1265Sandy10/12/1988

 

2. I want the latest service request if there is dup under the same ID and same name. In this scenario I want 9667 for Ryan's service request. And 7891 for Chris. 

AccountNameservice_req
1232Ryan9667
1440Chris7891
1211May1209
1265Sandy1287

 

Many thanks!

3 REPLIES 3
SASKiwi
PROC Star

If you have multiple birth dates for the same person how do you know it is always the one with the latest service_req that is correct? If you code such a general rule it will apply to all people. 

miss2223
Fluorite | Level 6

Hi, Yes you are right. What we been told the latest update of the service_req has the correct information, we just presume thats the case. As we are just dealing with the data, it comes from the book. So I guess its fine to apply to all people. Thanks 

SASKiwi
PROC Star

Here's one way of getting the correct birth date. Would be worth trying on your actual data to see how it goes:

proc sql;
  create table want as
  select A.*
        ,C.birthday as birthday_correct
  from input as A
  left join
  (select Account
         ,max(enddate) as enddate_Max format = ddmmyy10.
   from input
   group by Account
  ) as B
  on A.Account = B.Account
  left join input as C
  on A.account = C.Account
  and B.enddate_Max = C.enddate
  ;
quit; 

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 294 views
  • 0 likes
  • 2 in conversation