<?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: Get column based on another column value in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Get-column-based-on-another-column-value/m-p/954790#M45651</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416856"&gt;@Kıymet&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to use WEIGHTED_PD columns based on YEAR_DIFF column. For example, if YEAR_DIFF=3 then NEW_COLUMN must get the value in column of WEIGHTED_PD3. However, it must get WEIGHTED_PD1 if YEAR_DIFF=0. Thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Kymet_0-1735586868402.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103410i8136334261C4781C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Kymet_0-1735586868402.png" alt="Kymet_0-1735586868402.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are you asking how to use YEAR_DIFF to index into an ARRAY?&amp;nbsp; Assuming you mean to use index of 1 when year_diff is less than 1 then perhaps just use a MAX() function call?&amp;nbsp; If the rule is more complex you might need to instead use an IF/THEN construct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you have 5 WEIGHTED_PDx variables in your dataset then you program might look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  array pd WEIGHTED_PD1-WEIGHTED_PD5;
 &amp;nbsp;new_column=pd[max(1,year_diff)];
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 30 Dec 2024 20:32:48 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-12-30T20:32:48Z</dc:date>
    <item>
      <title>Get column based on another column value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Get-column-based-on-another-column-value/m-p/954788#M45649</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to use WEIGHTED_PD columns based on YEAR_DIFF column. For example, if YEAR_DIFF=3 then NEW_COLUMN must get the value in column of WEIGHTED_PD3. However, it must get WEIGHTED_PD1 if YEAR_DIFF=0. Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Kymet_0-1735586868402.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103410i8136334261C4781C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Kymet_0-1735586868402.png" alt="Kymet_0-1735586868402.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2024 19:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Get-column-based-on-another-column-value/m-p/954788#M45649</guid>
      <dc:creator>Kıymet</dc:creator>
      <dc:date>2024-12-30T19:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: Get column based on another column value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Get-column-based-on-another-column-value/m-p/954789#M45650</link>
      <description>&lt;P&gt;There is no WEIGHTED_PD1 column.&lt;/P&gt;
&lt;P&gt;Please help us and provide data as working SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;) and not as a screen capture.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2024 19:56:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Get-column-based-on-another-column-value/m-p/954789#M45650</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-12-30T19:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Get column based on another column value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Get-column-based-on-another-column-value/m-p/954790#M45651</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416856"&gt;@Kıymet&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to use WEIGHTED_PD columns based on YEAR_DIFF column. For example, if YEAR_DIFF=3 then NEW_COLUMN must get the value in column of WEIGHTED_PD3. However, it must get WEIGHTED_PD1 if YEAR_DIFF=0. Thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Kymet_0-1735586868402.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103410i8136334261C4781C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Kymet_0-1735586868402.png" alt="Kymet_0-1735586868402.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are you asking how to use YEAR_DIFF to index into an ARRAY?&amp;nbsp; Assuming you mean to use index of 1 when year_diff is less than 1 then perhaps just use a MAX() function call?&amp;nbsp; If the rule is more complex you might need to instead use an IF/THEN construct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you have 5 WEIGHTED_PDx variables in your dataset then you program might look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  array pd WEIGHTED_PD1-WEIGHTED_PD5;
 &amp;nbsp;new_column=pd[max(1,year_diff)];
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Dec 2024 20:32:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Get-column-based-on-another-column-value/m-p/954790#M45651</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-30T20:32:48Z</dc:date>
    </item>
  </channel>
</rss>

