<?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 to know if any of ~250 variables meet a certain condition -- array and/or do loop? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-know-if-any-of-250-variables-meet-a-certain-condition/m-p/180050#M45921</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are the variables numeric?&amp;nbsp; Could be that.&amp;nbsp; Post some test data where it doesn't work as the following works fine:&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; dx_cat1=1; dx_cat2=5; dx_cat3=4; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; dx_cat1=3; dx_cat2=2; dx_cat3=7; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array dx_cat{3};&lt;/P&gt;&lt;P&gt;&amp;nbsp; if whichn(5, of dx_cat{*}) &amp;gt; 0 then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 21 Nov 2014 14:58:48 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2014-11-21T14:58:48Z</dc:date>
    <item>
      <title>Need to know if any of ~250 variables meet a certain condition -- array and/or do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-know-if-any-of-250-variables-meet-a-certain-condition/m-p/180047#M45918</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm working with Medicaid data, and I have a series of variables that represent all of the diagnosis categories that the doctor billed for during each visit.&amp;nbsp; There are about 250 variables, and they each have a sequentially numbered variable name: DX_cat_1, DX_cat_2 ... DX_cat_250.&amp;nbsp; If any of these variables have a value of 5, then it is considered a visit that involved a mental health diagnosis.&amp;nbsp; So here is the code I attempted, which doesn't work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA medicaid.&amp;amp;filename._DXcount;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*Initialize variable to represent if the visit included a mental health diagnosis*/&lt;/P&gt;&lt;P&gt;MHvisit = 0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DO i = 1 to 250 by 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF DX_cat_i = 5 THEN MHvisit = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; OUTPUT;&lt;/P&gt;&lt;P&gt;END;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Nov 2014 19:15:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-know-if-any-of-250-variables-meet-a-certain-condition/m-p/180047#M45918</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2014-11-20T19:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: Need to know if any of ~250 variables meet a certain condition -- array and/or do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-know-if-any-of-250-variables-meet-a-certain-condition/m-p/180048#M45919</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Close, you need to declare an array for the variables. You can loop or use the WHICHN function.&lt;/P&gt;&lt;P&gt;You'll output a line for ever DX_cAT though, effectively transposing it. Is that what you wanted? I'm assuming you only want the mental health visits. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;DATA medicaid.&amp;amp;filename._DXcount;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;/*Initialize variable to represent if the visit included a mental health diagnosis*/&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;MHvisit = 0;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; array dx_cat(250) dx_cat_1-dx_cat_250;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;DO i = 1 to 250 ;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF DX_cat(i) = 5 THEN MHvisit = 1;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;END;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if MHvisit=1 then output;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;RUN;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Or using whichn function:&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;DATA medicaid.&amp;amp;filename._DXcount;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;/*Initialize variable to represent if the visit included a mental health diagnosis*/&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;MHvisit = 0;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; array dx_cat(250) dx_cat_1-dx_cat_250;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;mhvisit=1;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if whichn(5, of dx_cat(*))&amp;gt;0 then output;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;RUN;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Nov 2014 19:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-know-if-any-of-250-variables-meet-a-certain-condition/m-p/180048#M45919</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-11-20T19:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: Need to know if any of ~250 variables meet a certain condition -- array and/or do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-know-if-any-of-250-variables-meet-a-certain-condition/m-p/180049#M45920</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No luck&lt;img id="smileysad" class="emoticon emoticon-smileysad" src="https://communities.sas.com/i/smilies/16x16_smiley-sad.png" alt="Smiley Sad" title="Smiley Sad" /&gt;&amp;nbsp; I tried it both ways.&amp;nbsp; The DO loop outputs a file with 250 variables and 0 observations.&amp;nbsp; The whichn version outputs a file with 249 variables and 0 observations. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the code I used (the DX_cat variables actually go up to 248).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA medicaid.&amp;amp;filename._DXcount;&lt;/P&gt;&lt;P&gt;/*Initialize variable to represent if the visit included a mental health diagnosis*/&lt;/P&gt;&lt;P&gt;MHvisit = 0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; array dx_cat(248) dx_cat_1-dx_cat_248;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DO i = 1 to 248;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF DX_cat(i) = 5 THEN MHvisit = 1;&lt;/P&gt;&lt;P&gt;END;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF MHvisit=1 THEN output;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA medicaid.&amp;amp;filename._DXcount;&lt;/P&gt;&lt;P&gt; /*Initialize variable to represent if the visit included a mental health diagnosis*/&lt;/P&gt;&lt;P&gt;MHvisit = 0;&lt;/P&gt;&lt;P&gt;array dx_cat(248) dx_cat_1-dx_cat_248;&lt;/P&gt;&lt;P&gt;mhvisit=1;&lt;/P&gt;&lt;P&gt;if whichn(5, of dx_cat(*))&amp;gt;0 then output;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Nov 2014 14:41:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-know-if-any-of-250-variables-meet-a-certain-condition/m-p/180049#M45920</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2014-11-21T14:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: Need to know if any of ~250 variables meet a certain condition -- array and/or do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-know-if-any-of-250-variables-meet-a-certain-condition/m-p/180050#M45921</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are the variables numeric?&amp;nbsp; Could be that.&amp;nbsp; Post some test data where it doesn't work as the following works fine:&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; dx_cat1=1; dx_cat2=5; dx_cat3=4; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; dx_cat1=3; dx_cat2=2; dx_cat3=7; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array dx_cat{3};&lt;/P&gt;&lt;P&gt;&amp;nbsp; if whichn(5, of dx_cat{*}) &amp;gt; 0 then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Nov 2014 14:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-know-if-any-of-250-variables-meet-a-certain-condition/m-p/180050#M45921</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-11-21T14:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: Need to know if any of ~250 variables meet a certain condition -- array and/or do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-know-if-any-of-250-variables-meet-a-certain-condition/m-p/180051#M45922</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would be very tempted to create an entirely new set of variables that are indicators.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Array dx_cat dx_cat: ;&lt;/P&gt;&lt;P&gt;array dx dx_1-dx_250 ;&lt;/P&gt;&lt;P&gt;do I = 1 to dim(dx_cat);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not missing(dx_cat&lt;I&gt;) then dx[dx_cat&lt;I&gt;]=1;&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;dx_5 would be your mental health visits and a 1 indicates that visit had that treatment. I would hope you would be able to assign appropriate variable labels to all of the 250 categories.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Nov 2014 15:55:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-know-if-any-of-250-variables-meet-a-certain-condition/m-p/180051#M45922</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-11-21T15:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: Need to know if any of ~250 variables meet a certain condition -- array and/or do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-know-if-any-of-250-variables-meet-a-certain-condition/m-p/180052#M45923</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Apparently the problem was that I didn't use separate input and output data sets.&amp;nbsp; Below is the final version of the code.&amp;nbsp; Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*******************************************************************************/&lt;/P&gt;&lt;P&gt;DATA medicaid.&amp;amp;filename._MHvisit; SET medicaid.&amp;amp;filename._DXcount;&lt;/P&gt;&lt;P&gt;/*Initialize variable to represent if the visit included a mental health diagnosis*/&lt;/P&gt;&lt;P&gt;MHvisit = 0;&lt;/P&gt;&lt;P&gt;array dx_cat{248} dx_cat_1-dx_cat_248;&lt;/P&gt;&lt;P&gt;DO i = 1 to 248;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF DX_cat(i) = 5 THEN MHvisit = 1;&lt;/P&gt;&lt;P&gt;END;&lt;/P&gt;&lt;P&gt;IF MHvisit=1 THEN output;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Nov 2014 16:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-know-if-any-of-250-variables-meet-a-certain-condition/m-p/180052#M45923</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2014-11-21T16:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Need to know if any of ~250 variables meet a certain condition -- array and/or do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-know-if-any-of-250-variables-meet-a-certain-condition/m-p/180053#M45924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And did you try the whichn() version?&amp;nbsp; It will be faster than a loop and reads easier?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Nov 2014 17:07:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-know-if-any-of-250-variables-meet-a-certain-condition/m-p/180053#M45924</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-11-21T17:07:09Z</dc:date>
    </item>
  </channel>
</rss>

