Many thanks for sharing this interesting code. I am trying to use this code in SAS but after the define…