<?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: Split row into mutiple rows by calculation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Split-row-into-mutiple-rows-by-calculation/m-p/359388#M274522</link>
    <description>&lt;P&gt;If you data came as is (esp.&amp;nbsp; your vol variables are following the ascending order, otherwise other steps will be needed), and&amp;nbsp;you want to&amp;nbsp;output every row for each vol, &amp;nbsp;here is another alternative:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	input Geocode$   Vol1  Vol2   Vol3 Vol13;
	cards;
NATION       2        3       5                 4
;
run;

data want;
	set test;
	array vol vol:;
	length period $ 20;

	do over vol;
		period=catx('-',compress(vname(vol),,'kd'),'Month');
		current_vol+vol;
		output;
	end;

	call missing(current_vol);
	drop vol:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 May 2017 14:25:36 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2017-05-17T14:25:36Z</dc:date>
    <item>
      <title>Split row into mutiple rows by calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-row-into-mutiple-rows-by-calculation/m-p/359324#M274519</link>
      <description>&lt;P&gt;Geocode &amp;nbsp; Vol1 &amp;nbsp;Vol2 &amp;nbsp; Vol3...........Vol13&lt;/P&gt;&lt;P&gt;NATION &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have single row data entries in this format. I want to add a new colums 'Period' &amp;nbsp;and 'Current_Vol' for every row&amp;nbsp;&lt;/P&gt;&lt;P&gt;i.e&lt;/P&gt;&lt;P&gt;if Period = 1- Month then Current_Vol = Vol1&lt;/P&gt;&lt;P&gt;if Period = 3- Month then Current_Vol = Sum(Vol1-Vol3)&lt;/P&gt;&lt;P&gt;if Period = 6 Month then &amp;nbsp;Current Vol = Sum(Vol1-Vol6)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thus I want display to be as follow&lt;/P&gt;&lt;P&gt;GeoCode &amp;nbsp; &amp;nbsp; Period &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Current_Vol&lt;/P&gt;&lt;P&gt;NATION &amp;nbsp; &amp;nbsp; &amp;nbsp;1- Month &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;NATION &amp;nbsp; &amp;nbsp; &amp;nbsp;3-Month &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;&lt;P&gt;NATION &amp;nbsp; &amp;nbsp; &amp;nbsp;6-Month &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 10:36:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-row-into-mutiple-rows-by-calculation/m-p/359324#M274519</guid>
      <dc:creator>purveshrana</dc:creator>
      <dc:date>2017-05-17T10:36:32Z</dc:date>
    </item>
    <item>
      <title>Re: Split row into mutiple rows by calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-row-into-mutiple-rows-by-calculation/m-p/359326#M274520</link>
      <description>&lt;P&gt;Do refer to the posting guidance when posting a new question, post test data as a datastep, clearly show the problem. &amp;nbsp;I don't for instance get where period comes in. &amp;nbsp;Anyways, you almost have the code there:&lt;/P&gt;
&lt;PRE&gt;data have;&lt;BR /&gt; Geocode="NATION"; Vol1=2; Vol2=3; Vol3=5; vol4=4; vol5=7; vol6=3;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want (keep=geocode period current_vol);&lt;BR /&gt; set have;&lt;BR /&gt; array v{*} vol:;&lt;BR /&gt; do i=1,3,6;&lt;BR /&gt;   period=catx("-",put(i,best.),"Month");&lt;BR /&gt;   current_vol=sum(v{1}--v{i});&lt;BR /&gt;   output;&lt;BR /&gt; end;&lt;BR /&gt;run;       
  &lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2017 10:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-row-into-mutiple-rows-by-calculation/m-p/359326#M274520</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-17T10:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Split row into mutiple rows by calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-row-into-mutiple-rows-by-calculation/m-p/359332#M274521</link>
      <description>&lt;P&gt;Given that you have nearly spelled out the proper statements, it would be easy to fix them and use them in a DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;Period='1-Month';&lt;/P&gt;
&lt;P&gt;Current_Vol = vol1;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;period='3-Month';&lt;/P&gt;
&lt;P&gt;Current_Vol = sum(of vol1-vol3);&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;period='6-Month';&lt;/P&gt;
&lt;P&gt;Current_Vol = sum(of vol1-vol6);&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;keep GeoCode Period Current_Vol;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc print data=want;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 10:53:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-row-into-mutiple-rows-by-calculation/m-p/359332#M274521</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-05-17T10:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: Split row into mutiple rows by calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-row-into-mutiple-rows-by-calculation/m-p/359388#M274522</link>
      <description>&lt;P&gt;If you data came as is (esp.&amp;nbsp; your vol variables are following the ascending order, otherwise other steps will be needed), and&amp;nbsp;you want to&amp;nbsp;output every row for each vol, &amp;nbsp;here is another alternative:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	input Geocode$   Vol1  Vol2   Vol3 Vol13;
	cards;
NATION       2        3       5                 4
;
run;

data want;
	set test;
	array vol vol:;
	length period $ 20;

	do over vol;
		period=catx('-',compress(vname(vol),,'kd'),'Month');
		current_vol+vol;
		output;
	end;

	call missing(current_vol);
	drop vol:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 14:25:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-row-into-mutiple-rows-by-calculation/m-p/359388#M274522</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2017-05-17T14:25:36Z</dc:date>
    </item>
  </channel>
</rss>

