<?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: Flatten data variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673322#M202538</link>
    <description />
    <pubDate>Thu, 03 Sep 2020 21:54:23 GMT</pubDate>
    <dc:creator>nirsan</dc:creator>
    <dc:date>2020-09-03T21:54:23Z</dc:date>
    <item>
      <title>Flatten data variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673277#M202507</link>
      <description />
      <pubDate>Thu, 03 Sep 2020 21:53:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673277#M202507</guid>
      <dc:creator>nirsan</dc:creator>
      <dc:date>2020-09-03T21:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten data variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673283#M202511</link>
      <description>&lt;P&gt;1. Use PROC TRANSPOSE so the variables are named properly.&lt;BR /&gt;2. Use a shortcut reference to your variables health with the colon after acts as a wildcard. health_: will reference all variables that start with health. You'll need to use arrays for this. &lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array _myvars(*) health_:; *includes all variables that start with health_ ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here's a tutorial on using Arrays in SAS&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-arrays/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-arrays/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a reference that illustrates how to refer to variables and datasets in a short cut list:&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2020 21:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673283#M202511</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-29T21:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten data variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673293#M202517</link>
      <description>&lt;P&gt;Having a list of variables with common prefix and a suffix as serial numbers&lt;/P&gt;
&lt;P&gt;like:&lt;/P&gt;
&lt;PRE&gt;health_1 health_2 health_3 health_4 health_5 health_6 health_7 health_8 health_9 health_10 health_11 health_12.&lt;/PRE&gt;
&lt;P&gt;you can shorten it to&amp;nbsp;&lt;STRONG&gt;health_1 - health_12;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In some sas functions you can use the abbreviation&amp;nbsp;&lt;STRONG&gt;health_:&lt;/STRONG&gt; - to relate to all variables starting with health_, doesn't matter how many variables there are with this prefix or what suffixes they have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In case you are checking just &lt;U&gt;one&lt;/U&gt; value, it is preferred to check:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; if health_&lt;/STRONG&gt;n&lt;STRONG&gt; = 1&amp;nbsp;&lt;/STRONG&gt;instead&amp;nbsp;&lt;STRONG&gt;if health_&lt;/STRONG&gt;n&amp;nbsp;&lt;STRONG&gt;in(1).&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead writing:&lt;/P&gt;
&lt;PRE&gt;if health_1 in (1) or health_2 in (1) or health_3 in (1) or health_4 in (1) health_5 in (1) or health_6 in (1) or health_7 in (1) or health_8 in (1) or health_9 in (1) or health_10 in (1) health_11 in (1) or health_12 in (1) then health=1;&lt;/PRE&gt;
&lt;P&gt;you can use next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array hl {*} health_1 - health_12;
health = 1;
do i=1 to dim(hl);
    if hl(i) ne 1 then health = 0;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;that means that if any of the health conditions is not 1 then the final flag health is 0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope that satisfies what you look for.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2020 19:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673293#M202517</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-07-29T19:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten data variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673322#M202538</link>
      <description />
      <pubDate>Thu, 03 Sep 2020 21:54:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673322#M202538</guid>
      <dc:creator>nirsan</dc:creator>
      <dc:date>2020-09-03T21:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten data variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673326#M202541</link>
      <description>WHICHC()&lt;BR /&gt;&lt;BR /&gt;heatlh = whichc('1', of hl(*))&amp;gt;0;</description>
      <pubDate>Wed, 29 Jul 2020 22:40:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673326#M202541</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-29T22:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten data variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673586#M202666</link>
      <description />
      <pubDate>Thu, 03 Sep 2020 21:55:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673586#M202666</guid>
      <dc:creator>nirsan</dc:creator>
      <dc:date>2020-09-03T21:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten data variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673588#M202667</link>
      <description>Two loops, one to loop as indicated and another to loop over the list of diagnosis as well. You'll want to explore how you can leave loops once your condition is satisfied.</description>
      <pubDate>Thu, 30 Jul 2020 22:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673588#M202667</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-30T22:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten data variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673593#M202670</link>
      <description />
      <pubDate>Thu, 03 Sep 2020 21:55:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673593#M202670</guid>
      <dc:creator>nirsan</dc:creator>
      <dc:date>2020-09-03T21:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten data variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673602#M202675</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2020 21:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673602#M202675</guid>
      <dc:creator>nirsan</dc:creator>
      <dc:date>2020-09-03T21:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten data variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673616#M202685</link>
      <description>&lt;P&gt;You asked for "&lt;SPAN&gt;Can you please suggest what is the wrong with the following code?" -&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;in such case it is better to post the log, using the &amp;lt;/&amp;gt; icon.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As &amp;amp;hlth is a list of values you need change next line, from&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if hl(i) ne &amp;amp;hlth then health_ = 0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;into:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if hl(i) in &amp;amp;hlth then health_ = 0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;without a log I cannot say if there are other issues.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 04:32:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673616#M202685</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-07-31T04:32:50Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten data variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673629#M202693</link>
      <description />
      <pubDate>Thu, 03 Sep 2020 21:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673629#M202693</guid>
      <dc:creator>nirsan</dc:creator>
      <dc:date>2020-09-03T21:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten data variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673641#M202700</link>
      <description>&lt;P&gt;At start few remarks:&lt;/P&gt;
&lt;P&gt;1) Post code using the "running men" icon, in order to show indent and color the code, to distinguish easilly between functions, keywards and literals.&lt;/P&gt;
&lt;P&gt;2) Though there is no error message in log, sometimes warnings may help and point at issues.&lt;/P&gt;
&lt;P&gt;3) The statement&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;%let hlth = %nrstr('10029104');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;assigns just one value to &amp;amp;hlth, then why assigning it to an ARRAY?&lt;/P&gt;
&lt;P&gt;there is no meaning of using IN () or whichc() -&lt;/P&gt;
&lt;P&gt;the whole code is not clear what you want to do.&lt;/P&gt;
&lt;P&gt;4) As it is a following post to a solved one, please rewrite this query as a new one.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 09:01:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/673641#M202700</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-07-31T09:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten data variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/674573#M203146</link>
      <description>&lt;P&gt;Thanks for your suggestion and time. I will follow your instructions in future posts. I just wanted to inform that I edited the last code to which you already replied. Please ignore it as it will be also posted as a new topic as you suggested. thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 20:32:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flatten-data-variables/m-p/674573#M203146</guid>
      <dc:creator>nirsan</dc:creator>
      <dc:date>2020-08-04T20:32:48Z</dc:date>
    </item>
  </channel>
</rss>

