Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SAS code to identify different values in multiple rows according to one subject

the following data structure is given:

ID CASE VALUE DUMMY
123 4736 E10 1
123 1254 N65 0
123 0997 E11 1
123 7655 x 0
987 1234 x 0
987 6376 E10 1
987 0980 E18 0

I want to know: How can i create a new variable that includes if someone actually has the combination of E10 AND E11 (0,1) as follows:

ID CASE VALUE DUMMY Has the combination
123 4736 E10 1 1
123 1254 N65 0 1
123 0997 E11 1 1
123 7655 x 0 1
987 1234 x 0 0
987 6376 E10 1 0
987 0980 E18 0 0

Thanks in advance,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

PP

>Solution :

Assumption is that the data is already sorted by id.

data want;
    do until (last.id);
        set have;
        by id;
        if value = 'E10' then E10 = 1;
        if value = 'E11' then E11 = 1;
    end;

    do until (last.id);
        set have;
        by id;
        if E10 = 1 and E11 = 1 then combination = 1;
        else combination = 0;
        output;
    end;

    drop E:;
run;
 id   case  value  dummy  combination
123   4736   E10     1        1
123   1254   N65     0        1
123   997    E11     1        1
123   7655    x      0        1
987   1234    x      0        0
987   6376   E10     1        0
987   980    E18     0        0
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading