<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Identify value combinations in dataset based on reference file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874482#M345513</link>
    <description>Yes correct, and yes need to know the reason why the patient was flagged, but this can be derived from the row NUM in the reference file (e.g. in the reference file, let's suppose row #1 means bowel resection (coded as VALUE7) and cyst removal surgical (coded as value1, value999, value2309, or value17) procedures).&lt;BR /&gt;&lt;BR /&gt;So if VALUE7 and one of the values from COMB2 column in the reference file are found in the dataset, then NUM #1 might be returned, which can then be used to explain the "high risk procedures" - if that makes sense?</description>
    <pubDate>Mon, 08 May 2023 16:05:29 GMT</pubDate>
    <dc:creator>Epi_Stats</dc:creator>
    <dc:date>2023-05-08T16:05:29Z</dc:date>
    <item>
      <title>Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874464#M345499</link>
      <description>&lt;P&gt;I have a large dataset with many observations (dataset). Each observation has at least 2 values (e.g. value1, value5).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data dataset;
	input ID A $ B $ C $ D $ E $ F $ ;
datalines ;
1 value27 value31 value101 value999 value1 value7
2 value999 value1 value101 value8 value1 value886
3 value200 value31 value101 value49 value1 value3
4 value78 value531 value1 value2309 value12 value7
5 value200 value3 value2141 value919 value981 value234
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also have a reference file (reference) which contains 3 columns (NUM COMB1 and COMB2), and I want to use this file to identify all observations in the dataset which contain certain combinations of values (e.g. observation #4 in the dataset contains &lt;STRONG&gt;value2309 and value7&lt;/STRONG&gt; which &lt;STRONG&gt;is a combination&lt;/STRONG&gt; found in the reference file), therefore observation #4 should be flagged in some way to indicate that the dataset contains this combination.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data reference;
Input NUM COMB1 $ COMB2 $; 
datalines; 
1 value7 value1, value999, value2309, value17
2 value200 value3, value24, value883, value223
3 value12 value1, value234, value914, value981
4 value8 value999, value782, value888
5 value116 value26, value1
6 value900 value2, value9
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to do this using an array, but for some reason my array was only reading the first value in COMB2 column (e.g. Value7 from COMB1 and Value1 from COMB2, but not &lt;STRONG&gt;Value7 and Value999&lt;/STRONG&gt;, &lt;STRONG&gt;Value7 and Value2309&lt;/STRONG&gt;, etc. which meant some combinations were not being flagged).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am unable to share the array I was using, but would be grateful if anyone could offer a solution/method to what I’m trying to achieve?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 14:51:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874464#M345499</guid>
      <dc:creator>Epi_Stats</dc:creator>
      <dc:date>2023-05-08T14:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874468#M345503</link>
      <description>&lt;P&gt;Please verify that the reference data is being generated correctly. I think you have too many comma's in the dataset. &lt;BR /&gt;&lt;BR /&gt;Does the order of the combination matter? ie is value1 &amp;amp; Value 7 the same as value 7 &amp;amp; value 1. &lt;BR /&gt;&lt;BR /&gt;A quick method would be to use CALL SORT and use INDEX or FIND function to search for the strings together.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please also show what your expected output would be from this data to ensure we're understanding your requirements correctly.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 15:23:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874468#M345503</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-08T15:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874469#M345504</link>
      <description>&lt;P&gt;I'm confused about your REFERENCE dataset, when I run your code, I get:&lt;/P&gt;
&lt;PRE&gt;NUM     COMB1       COMB2

 1     value7      value1,
 2     value200    value3,
 3     value12     value1,
 4     value8      value999
 5     value116    value26,
 6     value900    value2,
&lt;/PRE&gt;
&lt;P&gt;Do you mean for Comb2 to be a character variables storing a comma-delimited list of values?&amp;nbsp; That will make this a mess to code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest you clarify the structure of the REFERENCE dataset, and then show the output you would WANT from your sample data.&amp;nbsp; I also think you should share the array code you have tried, using this sample data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, it might help if you can provide a logical description of the problem.&amp;nbsp; For example&amp;nbsp; something like "I have a dataset with one row per patient, and the variables are ICD-9 diagnosis codes.&amp;nbsp; I have another dataset that lists the combination of diagnosis codes that define a disease.&amp;nbsp; I want to add a disease flag to each patient, indicating which disease they have." If you're worried about confidentiality, it doesn't have to be the truth. : )&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 15:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874469#M345504</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-05-08T15:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874471#M345506</link>
      <description>&lt;P&gt;It might help to show the code you attempted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the approach is that you need to test every observation in Dataset against all of the combinations in Reference you likely will need to have a step that uses SQL to do that match up values before attempting to compare anything. Which means a different step if array is even likely.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW I see no way that your Reference data has only 3 variables. I see at least 5 if not 6 variables on the first row of Reference. So perhaps you need to reconsider your description and make sure that your data step actually makes a Reference set that looks like your description. You also need to show an a example of the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your Dataset is comparing just pairs of values from 6 variables then there are 15 combinations to consider ( Comb(6,2) function in SAS). Which means depending on your actual content of Reference that you may have 15 matches of combinations. So it is very important to show what the desired result looks like when one or more observations in Dataset actually matches more than one combination from Reference. "Flag in some way" and "to indicate that the dataset contains this combination" means that could be adding a considerable number of variables. 1 for each possible flag value and something else to hold the matched combination.&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 15:34:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874471#M345506</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-08T15:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874477#M345509</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;&amp;nbsp;I’m sorry, yes the reference file should look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;NUM&lt;/TD&gt;&lt;TD&gt;COMB1&lt;/TD&gt;&lt;TD&gt;COMB2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;value7&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;value1, value999, value2309, value17&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;value200&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;value3, value24, value883, value223&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;value12&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;value1, value234, value914, value981&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;value8&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;value999, value782, value888&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;SPAN&gt;value116&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;value26, value1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;, the order does not matter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;Yes, Comb2 is a comma-delimited list of values (the file is huge, I import it to SAS as a CSV – obviously generating a dataset like this in SAS using datalines is more involved that I had thought, sorry again).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Logical description:&lt;/P&gt;&lt;P&gt;It’s a medical dataset, and each row (ID) represents a different patient – the description you provide is basically what it is, different surgical interventions which each patient received during their time in hospital, and the reference file contains high risk combinations which I wish to identify in the medical dataset.&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 15:47:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874477#M345509</guid>
      <dc:creator>Epi_Stats</dc:creator>
      <dc:date>2023-05-08T15:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874480#M345511</link>
      <description>&lt;P&gt;So in order to be flagged, a patient would need to have both Comb1 and one value from Comb2, correct?&amp;nbsp; So a patient with VALUE7 and VALUE1 would be flagged per the first row of the reference table, but a patient with VALUE1 and VALUE999 would not be flagged?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you need to know the reason(s) a patient was flagged (i.e. which row of the reference table flagged the patient), or just the fact that the patient was flagged?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 15:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874480#M345511</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-05-08T15:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874482#M345513</link>
      <description>Yes correct, and yes need to know the reason why the patient was flagged, but this can be derived from the row NUM in the reference file (e.g. in the reference file, let's suppose row #1 means bowel resection (coded as VALUE7) and cyst removal surgical (coded as value1, value999, value2309, or value17) procedures).&lt;BR /&gt;&lt;BR /&gt;So if VALUE7 and one of the values from COMB2 column in the reference file are found in the dataset, then NUM #1 might be returned, which can then be used to explain the "high risk procedures" - if that makes sense?</description>
      <pubDate>Mon, 08 May 2023 16:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874482#M345513</guid>
      <dc:creator>Epi_Stats</dc:creator>
      <dc:date>2023-05-08T16:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874485#M345516</link>
      <description>&lt;P&gt;Yes, it's clear. And tricky.&amp;nbsp; I've thought of some bad approaches, involving multi-dimensional arrays (I always take multi-dimensional arrays as a sign of a bad approach. : )&amp;nbsp; Look forward to seeing what the community comes up with.&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 16:21:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874485#M345516</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-05-08T16:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874486#M345517</link>
      <description>What happens when you meet you multiple combinations?</description>
      <pubDate>Mon, 08 May 2023 16:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874486#M345517</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-08T16:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874490#M345520</link>
      <description>&lt;P&gt;Good use of temporary arrays here. I changed NUM to character to make it easier to define the array and because I don't know if it's possible to have an array that's both character and numeric.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data reference;
    infile cards dlm='|';
    Input NUM $ COMB1 $ COMB2 : $200.;
    datalines;
1| value7 | value1, value999, value2309, value17
2| value200 | value3, value24, value883, value223
3| value12 | value1, value234, value914, value981
4| value8 | value999, value782, value888
5| value116 |value26, value1
6| value900 | value2, value9
;
run;

data dataset;
    input ID A $ B $ C $ D $ E $ F $;
    datalines;
1 value27 value31 value101 value999 value1 value7
2 value999 value1 value101 value8 value1 value886
3 value200 value31 value101 value49 value1 value3
4 value78 value531 value1 value2309 value12 value7
5 value200 value3 value2141 value919 value981 value234
;
run;

proc sql noprint;
select count(*) into :num_flags from reference;
quit;

%put &amp;amp;num_flags.;

data flagged;


    *create temporary array to hold the reference data set;
    array M(&amp;amp;num_flags, 3) $ _temporary_;

    
    if _n_=1 then
        do j=1 to &amp;amp;num_flags;
            set Reference;
            M(j, 1)=NUM;
            M(j, 2)=COMB1;
            M(j, 3)=COMB2;
        end;
        
        
    set dataset;
    *loop over reference dataset rows;

    do i=1 to &amp;amp;num_flags;
        *determine number of words in COMB2;
        nwords=countw(M(i, 3));
        *if COMB1 is list of A-F then search for values in COMB2;

        if whichc(M(i, 2), of A--F) then
            do k=1 to nwords;
                *isolate each word;
                word=scan(M(i, 3), k, ",");
                *if found Comb2 item, then assign flag and output that line;

                if whichc(word, of A--F)&amp;gt;0 then
                    do;
                        flag=M(i, 1);
                        output;
                    end;
            end;
    end;
    drop NUM COMB1 COMB2 i j k nwords word;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 May 2023 16:42:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874490#M345520</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-08T16:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874506#M345527</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;! I accepted your code as the solution, but I might have more questions later, I hope that's ok. Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 17:49:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874506#M345527</guid>
      <dc:creator>Epi_Stats</dc:creator>
      <dc:date>2023-05-08T17:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874620#M345582</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;data reference;
    infile cards dlm='|';
    Input NUM $ COMB1 $ COMB2 : $200.;
    datalines;
1| value7 | value999, value10, value2309, value17
2| value200 | value24, value3, value883, value223
3| value12 | value1, value234, value914, value981
4| value8 | value782, value999, value888
5| value116 |value26, value1
6| value900 | value2, value9
;
run;

data dataset;
    input ID A $ B $ C $ D $ E $ F $;
    datalines;
1 value27 value31 value101 value999 value1 value7
2 value999 value1 value101 value8 value1 value886
3 value200 value31 value101 value49 value1 value3
4 value78 value7 value531 value2309 value112 value1
5 value200 value3 value2141 value919 value981 value234
;
run;

proc sql noprint;
select count(*) into :num_flags from reference;
quit;

%put &amp;amp;num_flags.;

data flagged;


    *create temporary array to hold the reference data set;
    array M(&amp;amp;num_flags, 3) $ _temporary_;

    
    if _n_=1 then
        do j=1 to &amp;amp;num_flags;
            set Reference;
            M(j, 1)=NUM;
            M(j, 2)=COMB1;
            M(j, 3)=COMB2;
        end;
        
        
    set dataset;
    *loop over reference dataset rows;

    do i=1 to &amp;amp;num_flags;
        *determine number of words in COMB2;
        nwords=countw(M(i, 3));
        *if COMB1 is list of A-F then search for values in COMB2;

        if whichc(M(i, 2), of A--F) then
            do k=1 to nwords;
                *isolate each word;
                word=scan(M(i, 3), k, ",");
                *if found Comb2 item, then assign flag and output that line;

                if whichc(word, of A--F)&amp;gt;0 then
                    do;
                        flag=M(i, 1);
                        output;
                    end;
            end;
    end;
    drop NUM COMB1 COMB2 i j k nwords word;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Unfortunately I’m finding the same issue I was having with my original array, where combinations are only being identified if the COMB2 value occurs &lt;STRONG&gt;first in the list in the reference file&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the above example, the following combinations (&lt;STRONG&gt;below&amp;nbsp;in bold&lt;/STRONG&gt;) are present in the dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data dataset;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; input ID A $ B $ C $ D $ E $ F $;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;1 value27 value31 value101 value999 value1 value7 &lt;STRONG&gt;/* VALUE 7 &amp;amp; 999 (#1 in ref file) */&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;2 value999 value1 value101 value8 value1 value886 &lt;STRONG&gt;/* VALUE 8 &amp;amp; 999 (#4 in ref file) */&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;3 value200 value31 value101 value49 value1 value3 &lt;STRONG&gt;/* VALUE 200 &amp;amp; 3 (#2 in ref file) */&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;4 value78 value7 value531 value2309 value112 value1 &lt;STRONG&gt;/* VALUE 7 &amp;amp; 2309 (#1 in ref file) */&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;5 value200 value3 value2141 value919 value981 value234 &lt;STRONG&gt;/* VALUE 200 &amp;amp; 3 (#2 in ref file) */&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I run the code, only ID #1 from the reference file is flagged (as value999 appears as the first value in the COMB2 list. For the other combinations, the COMB2 value appears somewhere in the list after position 1, e.g. the 2nd row in the dataset has combination VALUE 999 &amp;amp; 8, this is ID 4 in the reference file where 999 appears as the 2nd value in COMB2 col).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I make the array read through all values in the COMB2 list for a match?&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 08:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874620#M345582</guid>
      <dc:creator>Epi_Stats</dc:creator>
      <dc:date>2023-05-09T08:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874621#M345583</link>
      <description>Hi ballardw, thank you for your help. I have now included desired results above</description>
      <pubDate>Tue, 09 May 2023 08:35:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874621#M345583</guid>
      <dc:creator>Epi_Stats</dc:creator>
      <dc:date>2023-05-09T08:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874685#M345603</link>
      <description>&lt;P&gt;Always check your data is read in correctly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The default length for a character variable is 8 characters. value2309 is 9 characters for example. The array also defaulted to 8 characters.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Adding a length statement fixed the issue for me.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data reference;
    infile cards dlm='|';
    Input NUM $ COMB1 $ COMB2 : $200.;
    datalines;
1| value7 | value999, value10, value2309, value17
2| value200 | value24, value3, value883, value223
3| value12 | value1, value234, value914, value981
4| value8 | value782, value999, value888
5| value116 |value26, value1
6| value900 | value2, value9
;
run;

data dataset;
    length a b c d e f $10.;
    input ID A $ B $ C $ D $ E $ F $;
    datalines;
1 value27 value31 value101 value999 value1 value7
2 value999 value1 value101 value8 value1 value886
3 value200 value31 value101 value49 value1 value3
4 value78 value7 value531 value2309 value112 value1
5 value200 value3 value2141 value919 value981 value234
;
run;

proc sql noprint;
select count(*) into :num_flags from reference;
quit;

%put &amp;amp;num_flags.;

data flagged;


    *create temporary array to hold the reference data set;
    array M(&amp;amp;num_flags, 3) $200. _temporary_;

    
    if _n_=1 then
        do j=1 to &amp;amp;num_flags;
            set Reference;
            M(j, 1)=NUM;
            M(j, 2)=COMB1;
            M(j, 3)=COMB2;
        end;
        
        
    set dataset;
    *loop over reference dataset rows;

    do i=1 to &amp;amp;num_flags;
        *determine number of words in COMB2;
        nwords=countw(M(i, 3));
        *if COMB1 is list of A-F then search for values in COMB2;
        
        put nwords;

        if whichc(M(i, 2), of A--F) then
            do k=1 to nwords;
                *isolate each word;
                word=scan(M(i, 3), k, ",");
            
                *if found Comb2 item, then assign flag and output that line;

                if whichc(compress(trim(word)), of A--F)&amp;gt;0 then
                    do;
                        flag=M(i, 1);
                        output;
                    end;
            end;
    end;
    drop NUM COMB1 COMB2 i j k nwords word;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 15:50:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874685#M345603</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-09T15:50:22Z</dc:date>
    </item>
    <item>
      <title>Re: Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874693#M345607</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;the length statement fixed it!!&lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 16:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874693#M345607</guid>
      <dc:creator>Epi_Stats</dc:creator>
      <dc:date>2023-05-09T16:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874695#M345608</link>
      <description>&lt;P&gt;The code is much simpler with "vertical" or "tall" datasets.&lt;/P&gt;
&lt;P&gt;So you have patient data with ID and ICDCODE.&lt;/P&gt;
&lt;P&gt;And you have category data with CATGORY ICDCODE and a third variable to indicate if the ICDCODE is for "COMB1" or "COMB2" let's call this STEP.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you just need to join and aggregate.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a.id
        , b.category
        , max( b.step&amp;nbsp;=&amp;nbsp;'COMB1'&amp;nbsp;) as&amp;nbsp;COMB1
        , max( b.step&amp;nbsp;=&amp;nbsp;'COMB2'&amp;nbsp;) as&amp;nbsp;COMB2
from patients a
left join categories b
on a.icdcode = b.icdcode
group by 1,2
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So now you get a dataset like:&lt;/P&gt;
&lt;PRE&gt;patient category comb1 comb2
101 DIABETES 1 0
101 STROKE 1 1
102 DIABETES 1 1
102 STROKE 0 0&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Performance might be difficult depending on the size.&amp;nbsp; But if you are using an RDMS to store the data and do the join they can usually do a good job with proper indexing (and for parallel systems proper partitioning).&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 16:09:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874695#M345608</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-09T16:09:29Z</dc:date>
    </item>
    <item>
      <title>Re: Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874698#M345610</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 16:27:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874698#M345610</guid>
      <dc:creator>Epi_Stats</dc:creator>
      <dc:date>2023-05-09T16:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: Identify value combinations in dataset based on reference file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874763#M345634</link>
      <description>&lt;P&gt;That's a lovely solution,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;.&amp;nbsp; I wasted several dog walks trying to think about potential SQL approaches and hash approaches, but never got to the point of even imagining one that I liked enough to try.&amp;nbsp; I had the idea of making things vertical, because life is usually better when things are vertical.&amp;nbsp; But I think I got stuck on thinking about pairs of ICD codes (I was going to have a control dataset with all pairs of ICD codes for each category), rather than treating them independently via your STEP variable.&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 21:04:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-value-combinations-in-dataset-based-on-reference-file/m-p/874763#M345634</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-05-09T21:04:34Z</dc:date>
    </item>
  </channel>
</rss>

