Hi there,
For your kind information, I am trying to identify only those records which have been submitted with some changes. For example in the table mentioned below, TYPE has been changed in the most recent report with reference to the earliest report submitted.
data have ;
format date_1 date9. ;
input id $ sp_num $ type $ date_1 yymmdd8.;
datalines;
101 a01 p 20160102
101 a01 b 20160103
102 b02 b 20160104
102 b02 b 20160105
103 c03 p 20160106
103 c03 p 20160107
103 c03 b 20160108
;
run;
data want ;
format date_1 date9. ;
input id $ sp_num $ type $ date_1 yymmdd8.;
datalines;
101 a01 b 20160103
103 c03 b 20160108
;
run;
Can anybody kindly guide me to get it.
Thank you in advance.
Regards,
I think I answered my own question. Are you looking to do something like?:
data want (drop=change); set have; by id sp_num; retain change; if first.sp_num then change=0; if type ne lag(type) and not first.sp_num then change=1; if change and last.sp_num then output; run;
Art, CEO, AnalystFinder.com
did you also want the following record in your want dataset?:
102 b02 b 20160105
Art, CEO, AnalystFinder.com
Hi art297,
As the value of type has not changed, that record is not included.
Regards,
I think I answered my own question. Are you looking to do something like?:
data want (drop=change); set have; by id sp_num; retain change; if first.sp_num then change=0; if type ne lag(type) and not first.sp_num then change=1; if change and last.sp_num then output; run;
Art, CEO, AnalystFinder.com
In order to identify all instances where type is different than the initial value for type, I'd suggest a slightly different approach:
data have ; format date_1 date9. ; input id $ sp_num $ type $ date_1 yymmdd8.; datalines; 101 a01 p 20160102 101 a01 b 20160103 102 b02 b 20160104 102 b02 b 20160105 103 c03 p 20160106 103 c03 p 20160107 103 c03 b 20160108 103 c03 b 20160109 ; run; data want (drop=change); set have; by id sp_num; retain first_type; if first.sp_num then first_type=type; else if type ne first_type then output; run;
Art, CEO, AnalystFinder.com
Hi art297,
Thanks for taking the pain to answer my silly questions. It has been a good learning experience.
Regards,
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.