Hi Experts,
I want to merge my data in the below-given format. Kindly help me solve it.
data aaa;
input ID date1 mmddyy10. reg$;
format date1 date9.;
cards;
100 02/10/1990 V
100 05/09/1991 V
100 12/03/2000 V
101 05/05/2000 V
101 08/07/2010 V
101 04/03/2015 V
;
data bbb;
input ID date1 mmddyy10. reg$;
format date1 date9.;
cards;
100 02/10/1990 R
100 07/08/1995 R
100 12/03/2000 R
101 01/01/2001 R
101 08/07/2010 R
101 04/03/2015 R
;
Required Output :
ID | date1 | reg |
100 | 10-02-1990 | V |
100 | 09-05-1991 | V |
100 | 08-07-1995 | R |
100 | 03-12-2000 | V |
101 | 05-05-2000 | V |
101 | 01-01-2001 | R |
101 | 07-08-2010 | V |
101 | 03-04-2015 | V |
V - Visit; R - Record
If visit_date same as record_date then reg should 'V'
If record_date not in aaa table then that line should be included in the Current table/New Table with reg value of 'R'.
Please let me know If you required clarification.
Thanks in advance!
data ab;
merge aaa(rename=(reg=reg_a) in=in1) bbb(rename=(reg=reg_b) in=in2);
by id date1;
if reg_a='V' then reg='V';
else if reg_b='R' and not in1 then reg='R';
run;
In this small example, every case is handled by the two IF statements. Are there other possible cases?
data ab;
merge aaa(rename=(reg=reg_a) in=in1) bbb(rename=(reg=reg_b) in=in2);
by id date1;
if reg_a='V' then reg='V';
else if reg_b='R' and not in1 then reg='R';
run;
In this small example, every case is handled by the two IF statements. Are there other possible cases?
Thank you for your quick support @Astounding @PaigeMiller
Both your code works well. Have a great day!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.