<?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: Need the compliment of the following code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/666982#M199665</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299055"&gt;@montgomerybarre&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It feels that creating a lookup table instead of macro variables is eventually the better option.&lt;/P&gt;
&lt;P&gt;Why do you create this macro variable? What do you want to do with it?&lt;/P&gt;</description>
    <pubDate>Sun, 05 Jul 2020 03:16:12 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2020-07-05T03:16:12Z</dc:date>
    <item>
      <title>Need the compliment of the following code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/666913#M199631</link>
      <description>&lt;P&gt;I have the following code which captures 105 of 1400 possible diagnoses:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
	select DISTINCT quote(trim(dsc_diag_1)) INTO :BH_LIST separated by ' , '
	from claims1
	where (dsc_diag_1 like '% ANXIETY %' OR dsc_diag_1 like '% DEMENTIA %' OR dsc_diag_1 like '% MOOD %' OR dsc_diag_1 like '% SCHIZOPHRENIA %' OR dsc_diag_1 like '%SCHIZO%'
	OR dsc_diag_1 like '% DISSOCIATIVE %' OR dsc_diag_1 like '% STRESS %' OR dsc_diag_1 like '% DELUSIONAL %' OR dsc_diag_1 like '% PSYCHOACTIVE %'
	OR dsc_diag_1 like '% BEHAVIORAL %' OR dsc_diag_1 like '% MENTAL %' OR dsc_diag_1 like '% PERSONALITY %' OR dsc_diag_1 like '% INTELLECTUAL %'
	OR dsc_diag_1 like '% DEVELOPMENTAL %' OR dsc_diag_1 like '% EMOTIONAL %' OR dsc_diag_1 like '% PSYCH %' OR dsc_diag_1 like '% ALCOHOL %' 
	OR dsc_diag_1 like '% DEPRESSIVE %' OR dsc_diag_1 like '% DEPRESSION %' OR dsc_diag_1 like '% NEURO %' OR dsc_diag_1 like '% DELUSION %' 
	OR dsc_diag_1 like '% CANNABIS ABUSE%' OR dsc_diag_1 like '% CANNABIS USE%' OR dsc_diag_1 like '% CANNABIS DEPENDENCE%' 
	OR dsc_diag_1 like '% SEDATIVE, %' OR dsc_diag_1 like '% COCAINE %' OR dsc_diag_1 like '% NICOTINE %' 
	OR dsc_diag_1 like '% INHALANT %' OR dsc_diag_1 like '% STIMULANT %' OR dsc_diag_1 like '% SCHIZOAFFECTIVE %' OR dsc_diag_1 like '% PSYCHOSIS %'
	OR dsc_diag_1 like '% BIPOLAR %' OR dsc_diag_1 like '% DEPRESS %' OR dsc_diag_1 like '% CYCLOTHYMIC %' OR dsc_diag_1 like '% DYSTHIMIC %'
	OR dsc_diag_1 like '% PANIC %' OR dsc_diag_1 like '% ADJUSTMENT DISORDER %' OR dsc_diag_1 like '% POST-TRAUMATIC STRESS %' OR dsc_diag_1 like '% SOMATOFORM %'
	OR dsc_diag_1 like '% ANTISOCIAL %' OR dsc_diag_1 like '% BORDERLINE PERSONALITY %' OR dsc_diag_1 like '% EXPLOSIVE %' OR dsc_diag_1 like '% IMPULSE %'
	OR dsc_diag_1 like '% HYPERACTIVITY %' OR dsc_diag_1 like '% CONDUCT %' OR dsc_diag_1 like '% BEHAV/EMOTN %' OR dsc_diag_1 like '% IMPULSE %')
	and dsc_diag_1 not like '% OPIOID %' and dsc_diag_1 not like '% REMISSION %';
quit;&lt;/PRE&gt;&lt;P&gt;I am having trouble for some reason creating the compliment of this code, which would create a list of the other 1295 diagnoses codes. I cannot tell if my code is working, and the macro list is too long so the code stops running, or if my code is wrong altogether. I have tried a few variations on the following:&lt;/P&gt;&lt;PRE&gt;proc sql;
	select DISTINCT quote(trim(dsc_diag_1)) INTO :PH_LIST separated by ' , '
	from claims1
	where dsc_diag_1 not like '% ANXIETY %' and dsc_diag_1 not like '% DEMENTIA %' and dsc_diag_1 not like '% MOOD %' and dsc_diag_1 not like '% SCHIZOPHRENIA %' 
	or dsc_diag_1 not like '% SCHIZO %' and dsc_diag_1 not like '% SEDATIVE, %' and dsc_diag_1 not like '% COCAINE %' and dsc_diag_1 not like '% NICOTINE %' 
	or dsc_diag_1 not like '% DISSOCIATIVE %' and dsc_diag_1 not like '% DELUSIONAL %' and dsc_diag_1 not like '% PSYCHOACTIVE %'
	or dsc_diag_1 not like '% BEHAVIORAL %' and dsc_diag_1 not like '% MENTAL %' and dsc_diag_1 not like '% PERSONALITY %' and dsc_diag_1 not like '% INTELLECTUAL %'
	or dsc_diag_1 not like '% DEVELOPMENTAL %' and dsc_diag_1 not like '% EMOTIONAL %' and dsc_diag_1 not like '% PSYCH %' and dsc_diag_1 not like '% ALCOHOL %' 
	or dsc_diag_1 not like '% DEPRESSIVE %' and dsc_diag_1 not like '% DEPRESSION %' and dsc_diag_1 not like '% NEURO %' and dsc_diag_1 not like '% DELUSION %' 
	or dsc_diag_1 not like '% CANNABIS ABUSE%' and dsc_diag_1 not like '% CANNABIS USE%' and dsc_diag_1 not like '% CANNABIS DEPENDENCE %' 
	or dsc_diag_1 not like '% INHALANT %' and dsc_diag_1 not like '% STIMULANT %' and dsc_diag_1 not like '% SCHIZOAFFECTIVE %' and dsc_diag_1 not like '% PSYCHOSIS %'
	or dsc_diag_1 not like '% BIPOLAR %' and dsc_diag_1 not like '% DEPRESS %' and dsc_diag_1 not like '% CYCLOTHYMIC %' and dsc_diag_1 not like '% DYSTHIMIC %'
	or dsc_diag_1 not like '% PANIC %' and dsc_diag_1 not like '% ADJUSTMENT DISORDER %' and dsc_diag_1 not like '% POST-TRAUMATIC STRESS %' and dsc_diag_1 not like '% SOMATOFORM %'
	or dsc_diag_1 not like '% ANTISOCIAL %' and dsc_diag_1 not like '% BORDERLINE PERSONALITY %' and dsc_diag_1 not like '% EXPLOSIVE %' and dsc_diag_1 not like '% IMPULSE %'
	or dsc_diag_1 not like '% HYPERACTIVITY %' and dsc_diag_1 not like '% CONDUCT %' and dsc_diag_1 not like '% BEHAV/EMOTN %' and dsc_diag_1 not like '% IMPULSE %'
	or dsc_diag_1 not like '% OPIOID %' and dsc_diag_1 not like '% REMISSION %';
quit;&lt;/PRE&gt;&lt;P&gt;Thank you for your time,&lt;/P&gt;&lt;P&gt;Barrett&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 23:27:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/666913#M199631</guid>
      <dc:creator>montgomerybarre</dc:creator>
      <dc:date>2020-07-03T23:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need the compliment of the following code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/666923#M199635</link>
      <description>&lt;P&gt;I think you can put parentheses around the entire where expression, and prefix it with NOT, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	select DISTINCT quote(trim(dsc_diag_1)) INTO :BH_LIST separated by ' , '
	from claims1
	where  NOT (
 (dsc_diag_1 like '% ANXIETY %' OR dsc_diag_1 like '% DEMENTIA %' OR dsc_diag_1 like '% MOOD %' OR dsc_diag_1 like '% SCHIZOPHRENIA %' OR dsc_diag_1 like '%SCHIZO%'
	OR dsc_diag_1 like '% DISSOCIATIVE %' OR dsc_diag_1 like '% STRESS %' OR dsc_diag_1 like '% DELUSIONAL %' OR dsc_diag_1 like '% PSYCHOACTIVE %'
	OR dsc_diag_1 like '% BEHAVIORAL %' OR dsc_diag_1 like '% MENTAL %' OR dsc_diag_1 like '% PERSONALITY %' OR dsc_diag_1 like '% INTELLECTUAL %'
	OR dsc_diag_1 like '% DEVELOPMENTAL %' OR dsc_diag_1 like '% EMOTIONAL %' OR dsc_diag_1 like '% PSYCH %' OR dsc_diag_1 like '% ALCOHOL %' 
	OR dsc_diag_1 like '% DEPRESSIVE %' OR dsc_diag_1 like '% DEPRESSION %' OR dsc_diag_1 like '% NEURO %' OR dsc_diag_1 like '% DELUSION %' 
	OR dsc_diag_1 like '% CANNABIS ABUSE%' OR dsc_diag_1 like '% CANNABIS USE%' OR dsc_diag_1 like '% CANNABIS DEPENDENCE%' 
	OR dsc_diag_1 like '% SEDATIVE, %' OR dsc_diag_1 like '% COCAINE %' OR dsc_diag_1 like '% NICOTINE %' 
	OR dsc_diag_1 like '% INHALANT %' OR dsc_diag_1 like '% STIMULANT %' OR dsc_diag_1 like '% SCHIZOAFFECTIVE %' OR dsc_diag_1 like '% PSYCHOSIS %'
	OR dsc_diag_1 like '% BIPOLAR %' OR dsc_diag_1 like '% DEPRESS %' OR dsc_diag_1 like '% CYCLOTHYMIC %' OR dsc_diag_1 like '% DYSTHIMIC %'
	OR dsc_diag_1 like '% PANIC %' OR dsc_diag_1 like '% ADJUSTMENT DISORDER %' OR dsc_diag_1 like '% POST-TRAUMATIC STRESS %' OR dsc_diag_1 like '% SOMATOFORM %'
	OR dsc_diag_1 like '% ANTISOCIAL %' OR dsc_diag_1 like '% BORDERLINE PERSONALITY %' OR dsc_diag_1 like '% EXPLOSIVE %' OR dsc_diag_1 like '% IMPULSE %'
	OR dsc_diag_1 like '% HYPERACTIVITY %' OR dsc_diag_1 like '% CONDUCT %' OR dsc_diag_1 like '% BEHAV/EMOTN %' OR dsc_diag_1 like '% IMPULSE %')
	and dsc_diag_1 not like '% OPIOID %' and dsc_diag_1 not like '% REMISSION %'
  ) ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Jul 2020 03:43:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/666923#M199635</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-07-04T03:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Need the compliment of the following code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/666925#M199636</link>
      <description>&lt;P&gt;The maximum length of a macro variable value is 64K.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The LOG will indicate when the limit is exceeded by an &lt;CODE&gt;INTO :PH_LIST&lt;/CODE&gt; clause&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example log&lt;/P&gt;
&lt;PRE&gt;ERROR: The length of the value of the macro variable PH_LIST (65540) exceeds the maximum length
       (65534). The value has been truncated to 65534 characters.
&lt;/PRE&gt;
&lt;P&gt;The bigger issue is the miscoded converse classification logic&lt;/P&gt;
&lt;P&gt;- missing parenthesis&lt;/P&gt;
&lt;P&gt;- some internal OR's not changed to AND's&lt;/P&gt;
&lt;P&gt;- external AND's not changed to OR's&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Conceptually, the logic statement (BH) and it's compliment (PH) are&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BH: &lt;CODE&gt;( A&amp;nbsp; or&amp;nbsp; B&amp;nbsp; or&amp;nbsp; C) and ~D and ~E&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;PH: &lt;CODE&gt;(~A and ~B and ~C)&amp;nbsp; or&amp;nbsp; D&amp;nbsp; or&amp;nbsp; E&lt;/CODE&gt;&amp;nbsp; (i.e. logical compliment is negation)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The BH where statement&lt;/P&gt;
&lt;PRE&gt;where dsc_diag_1 not like '% ANXIETY %' and dsc_diag_1 not like '% DEMENTIA %' and dsc_diag_1 not like '% MOOD %' and dsc_diag_1 not like '% SCHIZOPHRENIA %' 
	or dsc_diag_1 not like '% SCHIZO %' and dsc_diag_1 not like '% SEDATIVE, %' and dsc_diag_1 not like '% COCAINE %' and dsc_diag_1 not like '% NICOTINE %' 
	or dsc_diag_1 not like '% DISSOCIATIVE %' and dsc_diag_1 not like '% DELUSIONAL %' and dsc_diag_1 not like '% PSYCHOACTIVE %'&lt;BR /&gt;        or ...&lt;BR /&gt;        or dsc_diag_1 not like '% OPIOID %' and dsc_diag_1 not like '% REMISSION %'&lt;/PRE&gt;
&lt;P&gt;Should be this ~BH statement&lt;/P&gt;
&lt;PRE&gt;where (&lt;BR /&gt;      dsc_diag_1 not like '% ANXIETY %' and dsc_diag_1 not like '% DEMENTIA %' and dsc_diag_1 not like '% MOOD %' and dsc_diag_1 not like '% SCHIZOPHRENIA %' 
AND dsc_diag_1 not like '% SCHIZO %' and dsc_diag_1 not like '% SEDATIVE, %' and dsc_diag_1 not like '% COCAINE %' and dsc_diag_1 not like '% NICOTINE %' 
AND dsc_diag_1 not like '% DISSOCIATIVE %' and dsc_diag_1 not like '% DELUSIONAL %' and dsc_diag_1 not like '% PSYCHOACTIVE %'&lt;BR /&gt;AND ...&lt;BR /&gt;      )
        or dsc_diag_1 like '% OPIOID %' or dsc_diag_1 like '% REMISSION %'&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 09:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/666925#M199636</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-07-05T09:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: Need the compliment of the following code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/666927#M199638</link>
      <description>&lt;P&gt;Try create both lists by next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
     create table BH_list as 
     select DISTINCT quote(trim(dsc_diag_1)) as __diag
               from claims where(  ... )  ;  /* capture the 105 diagnoses */
			   
     create table PH_list as 
      select DISTINCT quote(trim(dsc_diag_1)) as __diag
              from claims where __diag not in
               (select __diag  from BH_list);
			   
     select __diag into :BH_list separated by ' , ' from BH_list;
     select __diag into :PH_list separated by ' , ' from PH_list;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Jul 2020 07:39:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/666927#M199638</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-07-04T07:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: Need the compliment of the following code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/666935#M199641</link>
      <description>&lt;P class=" language-sas"&gt;I could compliment your code if you really insist, but I think you run the risk to exceed the maximum macro variable length.&lt;/P&gt;
&lt;P class=" language-sas"&gt;It might be better to create a table with the values you want, and use it as a look up.&lt;/P&gt;
&lt;P class=" language-sas"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=" language-sas"&gt;Also you could use the &lt;EM&gt;contain&lt;/EM&gt; operator, or its shortcut, for more compact code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where (DSC_DIAG_1 ? ' ANXIETY ' | DSC_DIAG_1 ? ' DEMENTIA '  ...&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>Sat, 04 Jul 2020 12:23:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/666935#M199641</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-07-04T12:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Need the compliment of the following code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/666941#M199646</link>
      <description>&lt;P&gt;You need to apply &lt;A href="https://en.wikipedia.org/wiki/De_Morgan%27s_laws#:~:text=In%20propositional%20logic%20and%20Boolean,both%20valid%20rules%20of%20inference.&amp;amp;text=The%20rules%20allow%20the%20expression,of%20each%20other%20via%20negation." target="_self"&gt;DeMorgans law.&lt;/A&gt;&amp;nbsp;in both directions.&lt;/P&gt;
&lt;P&gt;Your overall structure is&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;A and B and C&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which you can convert using&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;not (A and X and Y) = (not A) or (not X) or (not Y)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first part, A, is in the form&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;B or C or D ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which you can convert using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;not (B or C or D ) = (not B) and (not C) and (not D)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So the compliment of&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(B or C or D) and X and Y&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;((not B) and (not C) and (not D)) or (not X) or (not Y)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But why not just save a lot of time and just add NOT ( ) around the existing code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jul 2020 13:58:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/666941#M199646</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-04T13:58:56Z</dc:date>
    </item>
    <item>
      <title>Re: Need the compliment of the following code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/666958#M199656</link>
      <description>&lt;P&gt;Keep the diagnoses in a dataset, and create the code dynamically from there with call execute.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jul 2020 18:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/666958#M199656</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-04T18:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: Need the compliment of the following code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/666982#M199665</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299055"&gt;@montgomerybarre&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It feels that creating a lookup table instead of macro variables is eventually the better option.&lt;/P&gt;
&lt;P&gt;Why do you create this macro variable? What do you want to do with it?&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 03:16:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/666982#M199665</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-07-05T03:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: Need the compliment of the following code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/667029#M199681</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While everyone's comments about the logic were spot on, I've determined that logic is not the main issue. I have run different versions of the logic and I always get the same error about the macro variable truncation:&amp;nbsp;ERROR: The length of the value of the macro variable BH_LIST (65540) exceeds the maximum length (65534). The value has been truncated to 65534 characters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output in the log and results made me thing that an error in the logic was causing an overly-long macro list, but I've determined that even the correct list will be longer than a macro list can contain.&amp;nbsp;&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/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;could you direct me towards the statements or code that would create a data set from the proc sql code? I think you are right that this is the only way to move forward, but I've never done this before.&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/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;Agreed, I need to make a lookup table. I will use both of these sets of diagnosis codes in order to create counts of how many unique diagnoses each individual in my data set has been diagnosed with. I have already done this successfully with the BH_List, but the larger PH_list is presenting problems due to its size.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 18:22:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/667029#M199681</guid>
      <dc:creator>montgomerybarre</dc:creator>
      <dc:date>2020-07-05T18:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: Need the compliment of the following code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/667072#M199696</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299055"&gt;@montgomerybarre&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;....&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;Agreed, I need to make a lookup table. I will use both of these sets of diagnosis codes in order to create counts of how many unique diagnoses each individual in my data set has been diagnosed with. I have already done this successfully with the BH_List, but the larger PH_list is presenting problems due to its size.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I assume you don't have the DSM or ICD codes in your data and that's why you're using the diagnosis text. So once you've pulled out the diagnosis as per your selection how do you plan to count? By individual text or by some grouping? Looking at your selections there are variations in your diagnosis text. So for the case below would you want to have the two strings in the same group or would you want to count them as different groups?&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;OR dsc_diag_1 like '% CANNABIS ABUSE%' OR dsc_diag_1 like '% CANNABIS USE%'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What about creating a grouping variable first? You then can do any further selection or grouping using this grouping variable.&lt;/P&gt;
&lt;P&gt;What data volumes are you dealing with? How many rows does your biggest table have?.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 23:43:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/667072#M199696</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-07-05T23:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: Need the compliment of the following code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/667271#M199772</link>
      <description>&lt;P&gt;Yes we don't have a complete list of those codes which is why I need to comb through all the data to create our own categorizations. The end goal here is to create binary variables that capture whether the individual has ever been diagnosed with a behavioral health diagnosis (that first list of like % dx % you see) or a physical health diagnosis (will be the complementary set of diagnoses), and then also two continuous variables that count the number of unique behavioral health diagnoses and psychical health diagnoses. I used the following code to accomplish this for the diagnoses that fall into the BH_list macro list (there are 24 diagnosis variables total, hence the array):&lt;/P&gt;&lt;PRE&gt;title3'Check for BH related dx';
proc sql;
	select DISTINCT quote(trim(dsc_diag_1)) INTO :BH_LIST separated by ' , '
	from claims1
	where (dsc_diag_1 like '% ANXIETY %' OR dsc_diag_1 like '% DEMENTIA %' OR dsc_diag_1 like '% MOOD %' OR dsc_diag_1 like '% SCHIZOPHRENIA %' OR dsc_diag_1 like '%SCHIZO%'
	OR dsc_diag_1 like '% DISSOCIATIVE %' OR dsc_diag_1 like '% STRESS %' OR dsc_diag_1 like '% DELUSIONAL %' OR dsc_diag_1 like '% PSYCHOACTIVE %'
	OR dsc_diag_1 like '% BEHAVIORAL %' OR dsc_diag_1 like '% MENTAL %' OR dsc_diag_1 like '% PERSONALITY %' OR dsc_diag_1 like '% INTELLECTUAL %'
	OR dsc_diag_1 like '% DEVELOPMENTAL %' OR dsc_diag_1 like '% EMOTIONAL %' OR dsc_diag_1 like '% PSYCH %' OR dsc_diag_1 like '% ALCOHOL %' 
	OR dsc_diag_1 like '% DEPRESSIVE %' OR dsc_diag_1 like '% DEPRESSION %' OR dsc_diag_1 like '% NEURO %' OR dsc_diag_1 like '% DELUSION %' 
	OR dsc_diag_1 like '% CANNABIS ABUSE%' OR dsc_diag_1 like '% CANNABIS USE%' OR dsc_diag_1 like '% CANNABIS DEPENDENCE%' 
	OR dsc_diag_1 like '% SEDATIVE, %' OR dsc_diag_1 like '% COCAINE %' OR dsc_diag_1 like '% NICOTINE %' 
	OR dsc_diag_1 like '% INHALANT %' OR dsc_diag_1 like '% STIMULANT %' OR dsc_diag_1 like '% SCHIZOAFFECTIVE %' OR dsc_diag_1 like '% PSYCHOSIS %'
	OR dsc_diag_1 like '% BIPOLAR %' OR dsc_diag_1 like '% DEPRESS %' OR dsc_diag_1 like '% CYCLOTHYMIC %' OR dsc_diag_1 like '% DYSTHIMIC %'
	OR dsc_diag_1 like '% PANIC %' OR dsc_diag_1 like '% ADJUSTMENT DISORDER %' OR dsc_diag_1 like '% POST-TRAUMATIC STRESS %' OR dsc_diag_1 like '% SOMATOFORM %'
	OR dsc_diag_1 like '% ANTISOCIAL %' OR dsc_diag_1 like '% BORDERLINE PERSONALITY %' OR dsc_diag_1 like '% EXPLOSIVE %' OR dsc_diag_1 like '% IMPULSE %'
	OR dsc_diag_1 like '% HYPERACTIVITY %' OR dsc_diag_1 like '% CONDUCT %' OR dsc_diag_1 like '% BEHAV/EMOTN %' OR dsc_diag_1 like '% IMPULSE %')
	and dsc_diag_1 not like '% OPIOID %' and dsc_diag_1 not like '% REMISSION %';
quit;

data long;
   set claims1;
   array d dsc_diag_: ;
   length onediag $ 200;
   do i=1 to dim(d);
      if not missing(d[i]) then do;
         onediag=d[i];
         output;
      end;
   end;
   keep study_id onediag;
run;

proc sql;
   create table dcount as
   select study_id, count(*) as bh_complexity
   from (select distinct study_id,onediag
          from long)
   where onediag in (&amp;amp;BH_LIST)
   group by study_id ;
quit;&lt;BR /&gt;&lt;BR /&gt;data claims2;&lt;BR /&gt;merge claims1 dcount;&lt;BR /&gt;by study_id;&lt;BR /&gt;if bh_complexity = . then bh_complexity = 0;&lt;BR /&gt;label bh_complexity = 'count of beahvioral health diagnoses (opioids and remission dx excluded) per probationer';&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jul 2020 18:58:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/667271#M199772</guid>
      <dc:creator>montgomerybarre</dc:creator>
      <dc:date>2020-07-06T18:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: Need the compliment of the following code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/667358#M199821</link>
      <description>&lt;P&gt;1. Your list is impossible to read and maintain. So much so that it contains duplicates (IMPULSE is repeated, and BORDERLINE PERSONALITY is already flagged by PERSONALITY)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and the spacing is not always consistent (no space around SCHIZO) and that's impossible to see.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should write it differently so it can more easily be vetted. See below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you write as below, you can also flag the&amp;nbsp;&lt;SPAN&gt;individuals who have been diagnosed with a behavioural&amp;nbsp;health issues in one single step.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data CLAIMS2; 
  LIST = ' ADJUSTMENT DISORDER | ALCOHOL  ANTISOCIAL | ANXIETY' 
    || ' | BEHAVIORAL | BEHAV/EMOTN| BIPOLAR | BORDERLINE PERSONALITY' 
    || ' | CANNABIS ABUSE| CANNABIS USE| CANNABIS DEPENDENCE| COCAINE | CONDUCT | CYCLOTHYMIC' 
    || ' | DELUSION | DELUSIONAL | DEMENTIA | DEPRESS | DEPRESSIVE | DEPRESSION | DEVELOPMENTAL | DISSOCIATIVE | DYSTHIMIC' 
    || ' | EMOTIONAL | EXPLOSIVE' 
    || ' | HYPERACTIVITY'
    || ' | IMPULSE | INHALANT | INTELLECTUAL'
    || ' | MENTAL | MOOD' 
    || ' | NEURO | NICOTINE'
    || ' | PANIC | PERSONALITY | POST-TRAUMATIC STRESS | PSYCHOACTIVE | PSYCH | PSYCHOSIS' 
    || ' |SCHIZO| SCHIZOAFFECTIVE | SEDATIVE | SOMATOFORM | STIMULANT | STRESS ';
  set CLAIMS1;
  array D DSC_DIAG_: ;
  do I=1 to dim(D);
    if prxmatch('m/'||LIST||'/', D[I]) &amp;amp; ^index(' OPIOID ',D[I]) &amp;amp; ^index(' REMISSION ',D[I]) then MENTAL_FLAG=1;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jul 2020 06:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/667358#M199821</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-07-07T06:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: Need the compliment of the following code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/667361#M199824</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299055"&gt;@montgomerybarre&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&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/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;could you direct me towards the statements or code that would create a data set from the proc sql code? I think you are right that this is the only way to move forward, but I've never done this before.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Say you have this (abbreviated) SQL code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select *
  from have
  where
    dsc_diag_1 like '% ANXIETY %'
    or dsc_diag_1 like '% DEMENTIA %'
    or dsc_diag_1 like '% MOOD %'
    or dsc_diag_1 like '% SCHIZOPHRENIA %'
    or dsc_diag_1 like '%SCHIZO%'
    or dsc_diag_1 like '% DISSOCIATIVE %'
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Put all those codes into a dataset, which is unlimited in size for all purposes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lookup;
input cond_value $50.;
datalines;
% ANXIETY %
% DEMENTIA %
% MOOD %
% SCHIZOPHRENIA %
%SCHIZO%
% DISSOCIATIVE %
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you create the previous SQL step dynamically:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set lookup end=done;
if _n_ = 1 then call execute("
proc sql;
create table want as
  select *
  from have
  where
");
if _n_ &amp;gt; 1 then call execute(" or");
call execute(" dsc_diag_1 like '" !! strip(cond_value) !! "'");
if done then call execute("
;
quit;
");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can see how the original SQL step code is reflected in the data _null_ step for easier reading and maintenance.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jul 2020 06:29:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-the-compliment-of-the-following-code/m-p/667361#M199824</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-07T06:29:24Z</dc:date>
    </item>
  </channel>
</rss>

