<?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: Can I use an arrary to pick between variables and assign new variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-I-use-an-arrary-to-pick-between-variables-and-assign-new/m-p/489688#M127922</link>
    <description>&lt;P&gt;Use the MIN/MAX&amp;nbsp; or SMALLEST/LARGEST functions if you want the smallest values.&lt;/P&gt;
&lt;P&gt;WHICHN returns the index of the first occurrence of a single value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array cov(3) cov1-cov3;
array level(3);
array light(3);

CoV=smallest(1, of (cov(*)); *find smallest value;
index = whichn(CoV, of cov(*)); *find index of smallest value;

Level = level(index);
Light = Light(index);
 

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 24 Aug 2018 16:50:05 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-08-24T16:50:05Z</dc:date>
    <item>
      <title>Can I use an arrary to pick between variables and assign new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-use-an-arrary-to-pick-between-variables-and-assign-new/m-p/489681#M127919</link>
      <description>&lt;P&gt;I am working through an problem where I have merged together numerous data sets and am trying to efficiently have SAS select which dataset to assign to a final set of variables. An example of the variables in the data set would be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CoV1 Level1 Light1 Cov2 Level2 Light2 Cov3 Level3 Light3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently i am working through the data in a long form way with examples such as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IF CoV1 &amp;lt; Cov2 AND CoV1 &amp;lt; CoV3 THEN&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DO;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CoV=CoV1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Level=Level1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Light=Light1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END;&lt;/P&gt;&lt;P&gt;ELSE IF&amp;nbsp; CoV2 &amp;lt; CoV1 AND CoV2 &amp;lt; CoV3 THEN&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DO;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CoV=CoV2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Level=Level2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Light=Light2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END;&lt;/P&gt;&lt;P&gt;ELSE IF&amp;nbsp; CoV3 &amp;lt; CoV1 AND CoV3 &amp;lt; CoV2 THEN&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DO;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CoV=CoV3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Level=Level3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Light=Light3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Obviously this long form programming poses problems problems when the number of merged files grows, I feel like there is a far more efficient way to program this type of decision in SAS, possibly using an array or other tools in the datastep.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically for each record i am trying to determine the minimum of CoV(1-3) variable and assign the CoV, Level and Light from that data set to the new variables CoV, Level and Light.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Aug 2018 16:41:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-use-an-arrary-to-pick-between-variables-and-assign-new/m-p/489681#M127919</guid>
      <dc:creator>tgrandchamp</dc:creator>
      <dc:date>2018-08-24T16:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use an arrary to pick between variables and assign new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-use-an-arrary-to-pick-between-variables-and-assign-new/m-p/489688#M127922</link>
      <description>&lt;P&gt;Use the MIN/MAX&amp;nbsp; or SMALLEST/LARGEST functions if you want the smallest values.&lt;/P&gt;
&lt;P&gt;WHICHN returns the index of the first occurrence of a single value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array cov(3) cov1-cov3;
array level(3);
array light(3);

CoV=smallest(1, of (cov(*)); *find smallest value;
index = whichn(CoV, of cov(*)); *find index of smallest value;

Level = level(index);
Light = Light(index);
 

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Aug 2018 16:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-use-an-arrary-to-pick-between-variables-and-assign-new/m-p/489688#M127922</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-08-24T16:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use an arrary to pick between variables and assign new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-use-an-arrary-to-pick-between-variables-and-assign-new/m-p/489694#M127924</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have you tried the min function, e.g.:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cov = min(of cov1-cov3);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Aug 2018 16:55:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-use-an-arrary-to-pick-between-variables-and-assign-new/m-p/489694#M127924</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2018-08-24T16:55:27Z</dc:date>
    </item>
  </channel>
</rss>

