<?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: Storing Top Values in a column in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861933#M42432</link>
    <description>&lt;P&gt;So when I ask "what do you mean by top 3 values", you cannot answer with you want the "&lt;SPAN&gt;top 3 values". That doesn't explain anything.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Mar 2023 13:06:00 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-03-02T13:06:00Z</dc:date>
    <item>
      <title>Storing First 3 Values in a column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861927#M42428</link>
      <description>&lt;P&gt;Hi! I would like to store the top 3 values of every id &amp;amp; create a column out of it. And let's say there are only two values present, the columns should be blank&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data haveOne;&lt;BR /&gt;input id value $;&lt;BR /&gt;datalines;&lt;BR /&gt;1 ABC&lt;BR /&gt;1 EFG&lt;BR /&gt;1 XYZ&lt;BR /&gt;1 UVW&lt;BR /&gt;2 GHJ&lt;BR /&gt;2 XYZ&lt;BR /&gt;3 ABC;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;ABC&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/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gt;</description>
      <pubDate>Thu, 02 Mar 2023 13:18:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861927#M42428</guid>
      <dc:creator>shubham_d</dc:creator>
      <dc:date>2023-03-02T13:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: Storing Top Values in a column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861930#M42429</link>
      <description>&lt;P&gt;What do you mean by “top 3 values”, if the values are character strings?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2023 12:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861930#M42429</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-02T12:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Storing Top Values in a column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861931#M42430</link>
      <description>&lt;P&gt;ID = 3 is not in your data?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2023 12:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861931#M42430</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2023-03-02T12:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: Storing Top Values in a column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861932#M42431</link>
      <description>Hey! So these are already sorted values &amp;amp; I need to create a column of only top 3 values</description>
      <pubDate>Thu, 02 Mar 2023 13:04:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861932#M42431</guid>
      <dc:creator>shubham_d</dc:creator>
      <dc:date>2023-03-02T13:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: Storing Top Values in a column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861933#M42432</link>
      <description>&lt;P&gt;So when I ask "what do you mean by top 3 values", you cannot answer with you want the "&lt;SPAN&gt;top 3 values". That doesn't explain anything.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2023 13:06:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861933#M42432</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-02T13:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: Storing Top Values in a column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861935#M42433</link>
      <description>For a particular id, I want to store only the first 3 entries, does that make sense ? And if 3 entries are not present for a particular id, I still want the columns to be created but they will have blank values</description>
      <pubDate>Thu, 02 Mar 2023 13:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861935#M42433</guid>
      <dc:creator>shubham_d</dc:creator>
      <dc:date>2023-03-02T13:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: Storing Top Values in a column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861937#M42435</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/438962"&gt;@shubham_d&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;For a particular id, I want to store only the first 3 entries&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Got it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=haveone out=want(keep=id value_1-value_3) prefix=value_;
by id;
var value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2023 13:17:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861937#M42435</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-02T13:17:08Z</dc:date>
    </item>
    <item>
      <title>Re: Storing Top Values in a column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861940#M42436</link>
      <description>Sorry missed out the 3rd id in datalines. Updated it now&lt;BR /&gt;&lt;BR /&gt;ID 3 has only one entry &amp;amp; hence when the columns are created the value_1 will have the value &amp;amp; value_2 &amp;amp; value_3 columns will stay blank. I hope that helps.</description>
      <pubDate>Thu, 02 Mar 2023 13:20:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861940#M42436</guid>
      <dc:creator>shubham_d</dc:creator>
      <dc:date>2023-03-02T13:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: Storing Top Values in a column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861941#M42437</link>
      <description>Hey! Thanks, this helped. Appreciate your patience in understanding the question. Am new to SAS &amp;amp; aiming to be more efficient next time</description>
      <pubDate>Thu, 02 Mar 2023 13:23:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861941#M42437</guid>
      <dc:creator>shubham_d</dc:creator>
      <dc:date>2023-03-02T13:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: Storing First 3 Values in a column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861978#M42443</link>
      <description>&lt;P&gt;You can do it using an ARRAY.&lt;/P&gt;
&lt;P&gt;First let's create your dataset.&amp;nbsp; Remember to place the semicolon that ends the data step with in-line data on its own line. Otherwise anything on the line with semicolon is ignored. There is no need to add an extra RUN; statement after the end of the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id value $;
datalines;
1 ABC
1 EFG
1 XYZ
1 UVW
2 GHJ
2 XYZ
3 ABC
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So to know where in the array to place a value you need to count how many observation you have found.&amp;nbsp; Here is one way using a DO loop around the SET statement.&amp;nbsp; This helps as then there is no need to RETAIN the values since all of them for a given ID group are done in one iteration of the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
  do rows=1 by 1 until(last.id);
    set have;
    by id;
    array out $8 value_1-value_3;
    if rows in (1:3) then out[rows]=value;
  end;
  drop value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1677775718271.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81011iE45EB965E4E851C9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1677775718271.png" alt="Tom_0-1677775718271.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>Thu, 02 Mar 2023 16:48:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Storing-First-3-Values-in-a-column/m-p/861978#M42443</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-02T16:48:47Z</dc:date>
    </item>
  </channel>
</rss>

