<?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: How do I check if a variable includes certain values if this variable contains multiple values? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-if-a-variable-includes-certain-values-if-this/m-p/788664#M252202</link>
    <description>&lt;P&gt;Thanks for the reply! If I have multiple rows per ID, how should I code it?&lt;/P&gt;</description>
    <pubDate>Thu, 06 Jan 2022 15:08:01 GMT</pubDate>
    <dc:creator>Boon_Noob</dc:creator>
    <dc:date>2022-01-06T15:08:01Z</dc:date>
    <item>
      <title>How do I check if a variable includes certain values if this variable contains multiple values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-if-a-variable-includes-certain-values-if-this/m-p/788564#M252160</link>
      <description>&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Person&lt;/TD&gt;&lt;TD&gt;All the Diagnosis codes for this Person&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1,2,4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2,3,4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;5,6,7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1,2,3,4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;If I have a dataset that looks like this, where a variable column contains multiple values per row. &amp;nbsp;So one person can have multiple codes. Here I want to define a new variable that if a person's codes contains either 2 or 3, then new variable =1 otherwise new variable =0.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want something like this:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Diagnosis code&lt;/TD&gt;&lt;TD&gt;New_Var&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1,2,4&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2,3,4&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;5,6,7&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1,3,4&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 05 Jan 2022 22:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-if-a-variable-includes-certain-values-if-this/m-p/788564#M252160</guid>
      <dc:creator>Boon_Noob</dc:creator>
      <dc:date>2022-01-05T22:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I check if a variable includes certain values if this variable contains multiple values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-if-a-variable-includes-certain-values-if-this/m-p/788565#M252161</link>
      <description>&lt;P&gt;Assuming your dataset is named HAVE and your character variable with the list of codes is named DIAGNOSIS_CODE then use code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  new_var = indexw(diagnosis_code,'2') or indexw(diagnosis_code,'3');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Jan 2022 22:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-if-a-variable-includes-certain-values-if-this/m-p/788565#M252161</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-05T22:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I check if a variable includes certain values if this variable contains multiple values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-if-a-variable-includes-certain-values-if-this/m-p/788566#M252162</link>
      <description>FINDW() or restructure your data to a more logical structure that has each value in it's own column or mulitple rows per ID. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 05 Jan 2022 22:47:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-if-a-variable-includes-certain-values-if-this/m-p/788566#M252162</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-05T22:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I check if a variable includes certain values if this variable contains multiple values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-if-a-variable-includes-certain-values-if-this/m-p/788567#M252163</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Person	Diagnosis_codes :$10.;
cards;
1	1,2,4
2	2,3,4
3	5,6,7
4	1,2,3,4
;

data want;
  set have;
  New_Var=^^findc(Diagnosis_codes,'23');
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Jan 2022 22:49:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-if-a-variable-includes-certain-values-if-this/m-p/788567#M252163</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2022-01-05T22:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do I check if a variable includes certain values if this variable contains multiple values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-if-a-variable-includes-certain-values-if-this/m-p/788568#M252164</link>
      <description>&lt;P&gt;It helps to provide example data in the form of a data step so we have something to write code to test and at least your actual variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this should work for your specific example:&lt;/P&gt;
&lt;PRE&gt;data want; 
    set have;
    new_var = (index(diagnosiscodes,'2')&amp;gt;0 or index(diagnosiscodes,'3') &amp;gt; 0);
run;&lt;/PRE&gt;
&lt;P&gt;The index function returns a position number in the string searched. The first parameter is the string to search, the second is what to search for. If the value is not found then the function returns 0.&lt;/P&gt;
&lt;P&gt;SAS will return a value of 1 for "True" and 0 for "False". So comparisons are a quick way to create 1/0 coded values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will find in the long run that placing multiple values into a single variable is awkward to code with and may result in very complex processes that do not extend well when new values are added.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 22:52:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-if-a-variable-includes-certain-values-if-this/m-p/788568#M252164</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-05T22:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do I check if a variable includes certain values if this variable contains multiple values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-if-a-variable-includes-certain-values-if-this/m-p/788664#M252202</link>
      <description>&lt;P&gt;Thanks for the reply! If I have multiple rows per ID, how should I code it?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 15:08:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-if-a-variable-includes-certain-values-if-this/m-p/788664#M252202</guid>
      <dc:creator>Boon_Noob</dc:creator>
      <dc:date>2022-01-06T15:08:01Z</dc:date>
    </item>
  </channel>
</rss>

