Hi,
I need to list out the medical stages of the patients. In the output the values of each stage should be unique in order. I shared the example set below.
data have;
input ID Date1 mmddyy10. stages$10.;
format Date1 mmddyy10.;
cards;
123 02/05/2000 7,2,2
456 08/08/1999 5,5,1
789 07/02/2012 1,1
187 06/06/2003 7,9
753 12/12/1993 2,9,2,2,2
654 01/11/2001 2,9,2
321 04/05/2000 12,5,9,5
987 03/02/1999 14
178 05/06/1998 5
845 03/03/2020 9,9,9
159 09/08/2020 1,3,18
run;
Expected output :
stages | Stg |
7,2,2 | 7,2 |
5,5,1 | 5,1 |
1,1 | 1 |
7,9 | 7,9 |
2,9,2,2,2 | 9,2 |
2,9,2 | 9,2 |
12,5,9,5 | 12,9,5 |
14 | 14 |
5 | 5 |
9,9,9 | 9 |
1,3,18 | 1,3,18 |
The values should matches the corresponding ID and date.
Kindly suggest a code.
Thanks in advance!
HI @Sathish_jammy There are multiple ways to approach the solution to your question. The idea is to evaluate
1. what would be the shortest path or the quickest path?
2. Whether linear or random binary search
A slow linear could mean many approaches which will get the job done perhaps using REGEX and other methods and so forth. I personally would like to approach with a HASH solution as I am biased to approaches/methodology devised and taught by Guru Paul D
data have;
input ID Date1 mmddyy10. stages$10.;
format Date1 mmddyy10.;
cards;
123 02/05/2000 7,2,2
456 08/08/1999 5,5,1
789 07/02/2012 1,1
187 06/06/2003 7,9
753 12/12/1993 2,9,2,2,2
654 01/11/2001 2,9,2
321 04/05/2000 12,5,9,5
987 03/02/1999 14
178 05/06/1998 5
845 03/03/2020 9,9,9
159 09/08/2020 1,3,18
;
data want;
if _n_=1 then do;
dcl hash H () ;
h.definekey ("_temp") ;
h.definedone () ;
end;
set have;
length stg $100;
do _n_=1 to countw(stages,',');
_temp=scan(stages,_n_,',');
if h.check() ne 0 then do;
Stg=catx(',',Stg,_temp);
h.add();
end;
end;
h.clear();
keep stages stg;
run;
HI @Sathish_jammy There are multiple ways to approach the solution to your question. The idea is to evaluate
1. what would be the shortest path or the quickest path?
2. Whether linear or random binary search
A slow linear could mean many approaches which will get the job done perhaps using REGEX and other methods and so forth. I personally would like to approach with a HASH solution as I am biased to approaches/methodology devised and taught by Guru Paul D
data have;
input ID Date1 mmddyy10. stages$10.;
format Date1 mmddyy10.;
cards;
123 02/05/2000 7,2,2
456 08/08/1999 5,5,1
789 07/02/2012 1,1
187 06/06/2003 7,9
753 12/12/1993 2,9,2,2,2
654 01/11/2001 2,9,2
321 04/05/2000 12,5,9,5
987 03/02/1999 14
178 05/06/1998 5
845 03/03/2020 9,9,9
159 09/08/2020 1,3,18
;
data want;
if _n_=1 then do;
dcl hash H () ;
h.definekey ("_temp") ;
h.definedone () ;
end;
set have;
length stg $100;
do _n_=1 to countw(stages,',');
_temp=scan(stages,_n_,',');
if h.check() ne 0 then do;
Stg=catx(',',Stg,_temp);
h.add();
end;
end;
h.clear();
keep stages stg;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.