<?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: conditionally look for a value present across multi-variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/conditionally-look-for-a-value-present-across-multi-variables/m-p/685441#M207879</link>
    <description>&lt;P&gt;I strongly suggest that when you have variables that only take one value of interest that you code them as numeric with 1 as the value of interest.&lt;/P&gt;
&lt;P&gt;Then this question becomes trivial because you could SUM the variables and if the sum is 22 then "all" have the value.&lt;/P&gt;
&lt;P&gt;When you have character variables you have to COUNT how many have the characteristic&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;P&gt;count=0;&lt;/P&gt;
&lt;P&gt;array infection{*} klebsiella pneumonia acetobacter choristidium_diff acetobactor;&lt;BR /&gt;do i=1 to dim(infection);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if infection{i} ="X" then count=count+1;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;/* AFTER the loop see what your count is*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if count= dim(infection) then inf=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; else 0.&lt;/P&gt;</description>
    <pubDate>Mon, 21 Sep 2020 14:21:35 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-09-21T14:21:35Z</dc:date>
    <item>
      <title>conditionally look for a value present across multi-variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditionally-look-for-a-value-present-across-multi-variables/m-p/685421#M207874</link>
      <description>&lt;P&gt;Hi experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a list of variables where clinical responses have been captured for every clinical events happened to multiple patient came for diagnosis.&lt;/P&gt;
&lt;P&gt;there are about 35 variables named differently.&lt;/P&gt;
&lt;P&gt;subjid&amp;nbsp; klebsiella pneumonia acetobacter choristidium_diff ......etc (22 variables)&lt;/P&gt;
&lt;P&gt;0021&amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X&lt;/P&gt;
&lt;P&gt;0022&amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X&lt;/P&gt;
&lt;P&gt;0024&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X&lt;/P&gt;
&lt;P&gt;0025&amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X&lt;/P&gt;
&lt;P&gt;0028&amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X&lt;/P&gt;
&lt;P&gt;......... continued till 10,000 paticipants&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to make a new column which will be 1 if all the 22 columns have X. if there is blank in any of the 22 columns then it has be 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought of using arrays to solve this and written a below code, but doesn't seems to execute with the aim. IF anyone can help with modifying the code, that would be helpful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array infection{*}&amp;nbsp; klebsiella pneumonia acetobacter choristidium_diff acetobactor;&lt;BR /&gt;do i=1 to dim(infection);&lt;BR /&gt;if infection{i} ="X" then inf=1;else inf=0;&lt;BR /&gt;end;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 13:40:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditionally-look-for-a-value-present-across-multi-variables/m-p/685421#M207874</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2020-09-21T13:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: conditionally look for a value present across multi-variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditionally-look-for-a-value-present-across-multi-variables/m-p/685441#M207879</link>
      <description>&lt;P&gt;I strongly suggest that when you have variables that only take one value of interest that you code them as numeric with 1 as the value of interest.&lt;/P&gt;
&lt;P&gt;Then this question becomes trivial because you could SUM the variables and if the sum is 22 then "all" have the value.&lt;/P&gt;
&lt;P&gt;When you have character variables you have to COUNT how many have the characteristic&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;P&gt;count=0;&lt;/P&gt;
&lt;P&gt;array infection{*} klebsiella pneumonia acetobacter choristidium_diff acetobactor;&lt;BR /&gt;do i=1 to dim(infection);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if infection{i} ="X" then count=count+1;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;/* AFTER the loop see what your count is*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if count= dim(infection) then inf=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; else 0.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 14:21:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditionally-look-for-a-value-present-across-multi-variables/m-p/685441#M207879</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-21T14:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: conditionally look for a value present across multi-variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditionally-look-for-a-value-present-across-multi-variables/m-p/685453#M207883</link>
      <description>&lt;P&gt;If your diagnoses are in consecutive order on the data set, it is very easy to refer to them, e.g. as&amp;nbsp;&lt;SPAN&gt;klebsiella--acetobactor. If they are blank if not "X", you can use CATS and LENGTHN to get the number of X-es:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  inf=lengthn(cats(of klebsiella--acetobactor))=22;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;I used LENGTHN instead of LENGTH, so that the function will return a 0 (LENGTH returns 1 for an empty string) when there are no diagnoses, just in case you also want the actual number of diagnoses.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 14:56:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditionally-look-for-a-value-present-across-multi-variables/m-p/685453#M207883</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-09-21T14:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: conditionally look for a value present across multi-variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditionally-look-for-a-value-present-across-multi-variables/m-p/685660#M207983</link>
      <description>&lt;PRE&gt;data want;
 set have;
array infection{*} klebsiella pneumonia acetobacter choristidium_diff acetobactor;
if ' ' in infection then inf=0;
 else inf=1;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Sep 2020 11:40:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditionally-look-for-a-value-present-across-multi-variables/m-p/685660#M207983</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-09-22T11:40:58Z</dc:date>
    </item>
  </channel>
</rss>

