<?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: Expand rows in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Expand-rows/m-p/339480#M22544</link>
    <description>&lt;P&gt;For consideration&lt;/P&gt;
&lt;PRE&gt;data have;
   length Time_Period $ 18.;
   Time_Period ="7/2001 - 9/2001";output;
   Time_Period ="1/2001 - 3/2001";output;
   Time_Period ="5/2002 - 6/2002";output;
   Time_Period ="4/2001 - 6/2001";output;
   Time_Period ="10/2001 - 12/2001";output;
;
run;


proc sql;
   create table want as
   select * 
   from have
   order by input(scan(time_period,1,' '),anydtdtm32.)
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Mar 2017 23:37:43 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-03-08T23:37:43Z</dc:date>
    <item>
      <title>Expand rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Expand-rows/m-p/339069#M22516</link>
      <description>&lt;P&gt;We have two datasets:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* dataset A */
Period              num_1   num_2   num_3
4/2001 - 6/2001     62       14      35&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* dataset B */
Time_Period
1/2001 - 3/2001
4/2001 - 6/2001
7/2001 - 9/2001
10/2001 - 12/2001&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output dataset would look like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* dataset want */
Time_Period         num_1 num_2 num_3
1/2001 - 3/2001      0     0     0
4/2001 - 6/2001      62    14    35
7/2001 - 9/2001      0     0     0
10/2001 - 12/2001    0     0     0&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not sure how to achieve that? maybe merge or join?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 01:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Expand-rows/m-p/339069#M22516</guid>
      <dc:creator>ayin</dc:creator>
      <dc:date>2017-03-08T01:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: Expand rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Expand-rows/m-p/339078#M22518</link>
      <description>&lt;P&gt;Yes, a merge is what you want (or SQL, but then you will have issues on the output dataset's sort order). Note that if there is no match, you'll want to set&amp;nbsp;&lt;EM&gt;num_1-num_3&lt;/EM&gt; to 0; otherwise they'll be null.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge dataset_a(in=in_a rename=period=time_period)
      dataset_b;
by time_period;
if not in_a then do;
   num_1 = 0;
   num_2 = 0;
   num_3 = 0;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Mar 2017 01:49:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Expand-rows/m-p/339078#M22518</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-03-08T01:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: Expand rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Expand-rows/m-p/339282#M22534</link>
      <description>&lt;P&gt;A SQL left join would do the trick equally well. It can also be contructed in EG using the query builder.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	select b.time_period, coalesce(a.num_1, 0), coalesce(a.num_2, 0), coalesce(a.num_3, 0)
		from b left join a
			on a.time_period=b.time_period;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add an ORDER BY clause if you need the results sorted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 15:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Expand-rows/m-p/339282#M22534</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2017-03-08T15:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: Expand rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Expand-rows/m-p/339289#M22537</link>
      <description>It won't sort, though, because it's a text string… &lt;BR /&gt;</description>
      <pubDate>Wed, 08 Mar 2017 16:07:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Expand-rows/m-p/339289#M22537</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-03-08T16:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: Expand rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Expand-rows/m-p/339293#M22538</link>
      <description>True, sort of. It will sort but not in a date order. Merely alphabetically and indeed probably not what you want.&lt;BR /&gt;&lt;BR /&gt;- Jan</description>
      <pubDate>Wed, 08 Mar 2017 16:10:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Expand-rows/m-p/339293#M22538</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2017-03-08T16:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: Expand rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Expand-rows/m-p/339480#M22544</link>
      <description>&lt;P&gt;For consideration&lt;/P&gt;
&lt;PRE&gt;data have;
   length Time_Period $ 18.;
   Time_Period ="7/2001 - 9/2001";output;
   Time_Period ="1/2001 - 3/2001";output;
   Time_Period ="5/2002 - 6/2002";output;
   Time_Period ="4/2001 - 6/2001";output;
   Time_Period ="10/2001 - 12/2001";output;
;
run;


proc sql;
   create table want as
   select * 
   from have
   order by input(scan(time_period,1,' '),anydtdtm32.)
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 23:37:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Expand-rows/m-p/339480#M22544</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-08T23:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: Expand rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Expand-rows/m-p/339483#M22545</link>
      <description>A learning experience since I never knew about linguistic sorting. Thanks for that. Only, if you add rows for 2002 (01/2002...) it doesn't quite give the result I would hope for. Oh well, still added something to my bag of tricks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 08 Mar 2017 23:45:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Expand-rows/m-p/339483#M22545</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2017-03-08T23:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: Expand rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Expand-rows/m-p/339484#M22546</link>
      <description>That was in reply to a message that suddenly disappeared.</description>
      <pubDate>Wed, 08 Mar 2017 23:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Expand-rows/m-p/339484#M22546</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2017-03-08T23:49:19Z</dc:date>
    </item>
  </channel>
</rss>

