<?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 Need to derive the new columns from existing column and subract with previous values on month basis in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-to-derive-the-new-columns-from-existing-column-and-subract/m-p/685569#M207940</link>
    <description>&lt;P&gt;Hello All ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PRODUCT&amp;nbsp; &amp;nbsp; &amp;nbsp;MONTH&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;WHOLEALE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RETIAL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WS_OUT&amp;nbsp; &amp;nbsp; &amp;nbsp; RETIAL_OUT&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;CREDIT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01MAR2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12-0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20-0&lt;/P&gt;&lt;P&gt;CREDIT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01APR2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 35&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4-12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 35-20&lt;/P&gt;&lt;P&gt;CREDIT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01MAY2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 54&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2-4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;54-35&lt;/P&gt;&lt;P&gt;CREDIT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JUN2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 29&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3-2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;29-54&lt;/P&gt;&lt;P&gt;CREDIT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JUL2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11-3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 13-29&lt;/P&gt;&lt;P&gt;CREDIT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01AUG2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 98&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5-11&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 98-13&lt;/P&gt;&lt;P&gt;AVIA&lt;/P&gt;&lt;P&gt;MARG&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;from above table and i need to derived the new columns called WS_OUT and RETAIL_OUT&amp;nbsp; which i shown above.&lt;/P&gt;&lt;P&gt;And same I have multiple product's like AVIA,MARG,HELTH etc. for every months.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in advance for your help on this.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Sep 2020 03:29:31 GMT</pubDate>
    <dc:creator>Itharaju</dc:creator>
    <dc:date>2020-09-22T03:29:31Z</dc:date>
    <item>
      <title>Need to derive the new columns from existing column and subract with previous values on month basis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-derive-the-new-columns-from-existing-column-and-subract/m-p/685569#M207940</link>
      <description>&lt;P&gt;Hello All ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PRODUCT&amp;nbsp; &amp;nbsp; &amp;nbsp;MONTH&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;WHOLEALE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RETIAL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WS_OUT&amp;nbsp; &amp;nbsp; &amp;nbsp; RETIAL_OUT&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;CREDIT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01MAR2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12-0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20-0&lt;/P&gt;&lt;P&gt;CREDIT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01APR2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 35&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4-12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 35-20&lt;/P&gt;&lt;P&gt;CREDIT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01MAY2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 54&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2-4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;54-35&lt;/P&gt;&lt;P&gt;CREDIT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JUN2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 29&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3-2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;29-54&lt;/P&gt;&lt;P&gt;CREDIT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JUL2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11-3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 13-29&lt;/P&gt;&lt;P&gt;CREDIT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01AUG2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 98&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5-11&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 98-13&lt;/P&gt;&lt;P&gt;AVIA&lt;/P&gt;&lt;P&gt;MARG&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;from above table and i need to derived the new columns called WS_OUT and RETAIL_OUT&amp;nbsp; which i shown above.&lt;/P&gt;&lt;P&gt;And same I have multiple product's like AVIA,MARG,HELTH etc. for every months.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in advance for your help on this.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 03:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-derive-the-new-columns-from-existing-column-and-subract/m-p/685569#M207940</guid>
      <dc:creator>Itharaju</dc:creator>
      <dc:date>2020-09-22T03:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Need to derive the new columns from existing column and subract with previous values on month ba</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-derive-the-new-columns-from-existing-column-and-subract/m-p/685573#M207943</link>
      <description>&lt;P&gt;How about something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	Product_Data;
	INFILE	DATALINES4
		FIRSTOBS	=	2;
	FORMAT	Month		YYMMDDD10.;
	LENGTH	Product		$25
			Month		8
			Wholesale	$4
			Retail		$4
			;
	INPUT	Product		$
			Month		:	ANYDTDTE7.
			Wholesale	$
			Retail		$
			;
	DATALINES4;
PRODUCT     MONTH             WHOLEALE        RETIAL
CREDIT        01MAR2020            12                       20 
CREDIT        01APR2020             4                        35
CREDIT        01MAY2020             2                        54
CREDIT        01JUN2020             3                        29
CREDIT        01JUL2020             11                       13
CREDIT        01AUG2020            5                        98 
;;;;
RUN;

**------------------------------------------------------------------------------**;

DATA	Product_Data_And_Out;
	SET	Product_Data;
	DROP	_:;
	LENGTH	_Prior_Wholesale	$4;
	LENGTH	_Prior_Retail		$4;
	LENGTH	WS_Out				$10;
	LENGTH	Retail_Out			$10;
	RETAIN	_Prior_Wholesale;
	RETAIN	_Prior_Retail;

	IF	_N_				=	1	THEN
		DO;
			WS_OUT		=	CATS(Wholesale, '-', '0');
			Retail_OUT	=	CATS(Retail, 	'-', '0');
		END;
	ELSE
		DO;
			WS_OUT		=	CATS(Wholesale, '-', _Prior_Wholesale);
			Retail_OUT	=	CATS(Retail, 	'-', _Prior_Retail);
		END;

	OUTPUT;

	_Prior_Wholesale	=	Wholesale;
	_Prior_Retail		=	Retail;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1600747524509.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49627iB07A2B422B857F1F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1600747524509.png" alt="jimbarbour_0-1600747524509.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How does that look?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 04:05:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-derive-the-new-columns-from-existing-column-and-subract/m-p/685573#M207943</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-22T04:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: Need to derive the new columns from existing column and subract with previous values on month ba</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-derive-the-new-columns-from-existing-column-and-subract/m-p/685576#M207944</link>
      <description>&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ws_out = catx('-',wholeale,lag(wholeale));&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; retail_out&amp;nbsp; = catx('-',retail,lag(retail));&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 04:17:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-derive-the-new-columns-from-existing-column-and-subract/m-p/685576#M207944</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-09-22T04:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need to derive the new columns from existing column and subract with previous values on month ba</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-derive-the-new-columns-from-existing-column-and-subract/m-p/685585#M207947</link>
      <description>&lt;P&gt;The following data-step is just an extend&amp;nbsp; version of the answer posted by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt; taking into account that you " have multiple product's like AVIA,MARG,HELTH" and assuming that the data is at least grouped by product. The code is, of course, untested, because you have not provided data in usable form. &lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   by product notsorted;
   
   _wholesale = lag(wholesale);
   _retail = lag(retail);
   
   if first.product then do;
      _wholesale = 0;
      _retail = 0;
   end;
   
   ws_out = catx('-', wholesale, _wholesale);
   retail_out = catx('-', retail, _retail);
   
   drop _wholesale _retail;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Sep 2020 05:13:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-derive-the-new-columns-from-existing-column-and-subract/m-p/685585#M207947</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-09-22T05:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need to derive the new columns from existing column and subract with previous values on month ba</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-derive-the-new-columns-from-existing-column-and-subract/m-p/686034#M208108</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm="09"x;
format month yymmdds10.;
input PRODUCT $ MONTH:date9. WHOLESALE RETAIL;
datalines;
CREDIT	01MAR2020	12	20
CREDIT	01APR2020	4	35
CREDIT	01MAY2020	2	54
CREDIT	01JUN2020	3	29
CREDIT	01JUL2020	11	13
CREDIT	01AUG2020	5	98
;
run;

data want;
	set have;
	ws_out=cats(wholesale,"-",ifn(lag(wholesale)=.,0,lag(wholesale)));
	retail_out=cats(retail,"-",ifn(lag(retail)=.,0,lag(retail)));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Sep 2020 13:26:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-derive-the-new-columns-from-existing-column-and-subract/m-p/686034#M208108</guid>
      <dc:creator>hhinohar</dc:creator>
      <dc:date>2020-09-23T13:26:03Z</dc:date>
    </item>
  </channel>
</rss>

