<?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: How to get data presented in columns to separate rows? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-data-presented-in-columns-to-separate-rows/m-p/771069#M39629</link>
    <description>&lt;P&gt;You seem to haven't seen PROC TRANSPOSE yet.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose
  data=have
  out=want (rename=(_name_=product_id col1=value))
;
by id;
var '111'n--'999'n;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Replace 999 with the name of the rightmost column.&lt;/P&gt;</description>
    <pubDate>Wed, 29 Sep 2021 05:31:39 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-09-29T05:31:39Z</dc:date>
    <item>
      <title>How to get data presented in columns to separate rows?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-data-presented-in-columns-to-separate-rows/m-p/771067#M39628</link>
      <description>&lt;P&gt;Hello, I have a data as followed.&lt;/P&gt;&lt;PRE&gt;ID|111|112|113|211|222
001|0.03|0|0|3.2|2.1
002|0|0|4.21|35|0
003|24.1|0|0|0|11.7&lt;/PRE&gt;&lt;P&gt;ID is a customer ID and other column names are product ID numbers. I want to produce data which would be as followed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ID|Product ID|value
001|111|0.03
001|211|3.2
001|222|2.1
002|113|4.21
002|211|35
003|111|24.1
003|222|11.7&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem is that the code I am using is very long due to having so many product ID numbers in the real data. At the moment the code is as followed.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table products as
    select
      ID, '111' as product ID, '111'n as value
    from _data
    where '111'n &amp;gt; 0 and ID &amp;gt; 0
  union all
    select
      ID, '112' as product ID, '112'n as value
    from _data
    where '112'n &amp;gt; 0 and ID &amp;gt; 0;
  union all
    select
      ID, '113' as product ID, '113'n as value
    from _data
    where '113'n &amp;gt; 0 and ID &amp;gt; 0
  union all
    select
      ID, '211' as product ID, '211'n as value
    from _data
    where '211'n &amp;gt; 0 and ID &amp;gt; 0
  union all
    select
      ID, '222' as product ID, '222'n as value
    from _data
    where '222'n &amp;gt; 0 and ID &amp;gt; 0
  union all
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Due to having almost hundred product ID numbers the code ends up being very long. There must be a more convenient way to get the result I want. Is anyone able to help making my code shorter?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Sep 2021 05:21:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-data-presented-in-columns-to-separate-rows/m-p/771067#M39628</guid>
      <dc:creator>vuohi</dc:creator>
      <dc:date>2021-09-29T05:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to get data presented in columns to separate rows?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-data-presented-in-columns-to-separate-rows/m-p/771069#M39629</link>
      <description>&lt;P&gt;You seem to haven't seen PROC TRANSPOSE yet.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose
  data=have
  out=want (rename=(_name_=product_id col1=value))
;
by id;
var '111'n--'999'n;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Replace 999 with the name of the rightmost column.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Sep 2021 05:31:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-data-presented-in-columns-to-separate-rows/m-p/771069#M39629</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-29T05:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to get data presented in columns to separate rows?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-data-presented-in-columns-to-separate-rows/m-p/771077#M39631</link>
      <description>Thanks KurtBremser, this was a great solution! The only problem I encountered was that I needed to have the IDs in ascending order but it was easily fixed with proc sort.</description>
      <pubDate>Wed, 29 Sep 2021 07:10:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-data-presented-in-columns-to-separate-rows/m-p/771077#M39631</guid>
      <dc:creator>vuohi</dc:creator>
      <dc:date>2021-09-29T07:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to get data presented in columns to separate rows?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-data-presented-in-columns-to-separate-rows/m-p/771080#M39632</link>
      <description>&lt;P&gt;Note that the notation&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;varx--vary&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;grabs all variables that are &lt;U&gt;physically allocated&lt;/U&gt; between varx and vary.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var111-var999&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;OTOH would look for &lt;U&gt;all&lt;/U&gt; variables in the &lt;U&gt;range&lt;/U&gt;, meaning 889 all in all, without regard for their location within an observation..&lt;/P&gt;</description>
      <pubDate>Wed, 29 Sep 2021 07:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-data-presented-in-columns-to-separate-rows/m-p/771080#M39632</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-29T07:19:01Z</dc:date>
    </item>
  </channel>
</rss>

