<?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 How to create an additional record by adding values of two records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-additional-record-by-adding-values-of-two/m-p/687418#M208677</link>
    <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to create an additional record with sum values of two records. In the below output i need to create the red highlighted record.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data one;
input val$ n1 n2 total;
datalines;
cr 10 12 22 
pr 12 23 35
sd 23 24 47
ne 30 35 65
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please suggest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed:&lt;/P&gt;
&lt;P&gt;val&amp;nbsp; &amp;nbsp; &amp;nbsp; n1&amp;nbsp; n2&amp;nbsp; &amp;nbsp;total&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cr&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10 12 22 &lt;BR /&gt;pr&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12 23 35&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;cr/pr&amp;nbsp; &amp;nbsp; 22&amp;nbsp; 35&amp;nbsp; 57&lt;/FONT&gt;&lt;BR /&gt;sd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 23 24 47&lt;BR /&gt;ne&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30 35 65&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 05:44:04 GMT</pubDate>
    <dc:creator>knveraraju91</dc:creator>
    <dc:date>2020-09-29T05:44:04Z</dc:date>
    <item>
      <title>How to create an additional record by adding values of two records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-additional-record-by-adding-values-of-two/m-p/687418#M208677</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to create an additional record with sum values of two records. In the below output i need to create the red highlighted record.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data one;
input val$ n1 n2 total;
datalines;
cr 10 12 22 
pr 12 23 35
sd 23 24 47
ne 30 35 65
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please suggest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed:&lt;/P&gt;
&lt;P&gt;val&amp;nbsp; &amp;nbsp; &amp;nbsp; n1&amp;nbsp; n2&amp;nbsp; &amp;nbsp;total&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cr&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10 12 22 &lt;BR /&gt;pr&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12 23 35&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;cr/pr&amp;nbsp; &amp;nbsp; 22&amp;nbsp; 35&amp;nbsp; 57&lt;/FONT&gt;&lt;BR /&gt;sd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 23 24 47&lt;BR /&gt;ne&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30 35 65&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 05:44:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-additional-record-by-adding-values-of-two/m-p/687418#M208677</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2020-09-29T05:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an additional record by adding values of two records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-additional-record-by-adding-values-of-two/m-p/687423#M208681</link>
      <description>&lt;P&gt;What is the rule that identifies the observations that need to be added? Is it only the position in the dataset?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 06:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-additional-record-by-adding-values-of-two/m-p/687423#M208681</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-29T06:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an additional record by adding values of two records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-additional-record-by-adding-values-of-two/m-p/688101#M208977</link>
      <description>In my dataset there are only 4 obs. I need to add records with  val in(cr,pr) and create new variable cr/pr. Thank you. Please suggest</description>
      <pubDate>Thu, 01 Oct 2020 03:59:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-additional-record-by-adding-values-of-two/m-p/688101#M208977</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2020-10-01T03:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an additional record by adding values of two records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-additional-record-by-adding-values-of-two/m-p/688109#M208982</link>
      <description>&lt;P&gt;This isn't particularly elegant, but it will do the job if what you've posted is literally all you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
	DROP	_:;
	RETAIN	_CR	0;
	RETAIN	_CR_n1;
	RETAIN	_CR_n2;
	RETAIN	_CR_Total;

	INPUT	val$ n1 n2 total;

	if	 Val			=	'cr'	THEN
		DO;
			_CR			=	1;
			_CR_n1		=	n1;
			_CR_n2		=	n2;
			_CR_Total	=	Total;
		END;

	if	 Val			=	'pr'	THEN
		_PR				=	1;

	IF	_CR	AND	_PR			THEN
		DO;
			OUTPUT;
			Val			=	'cr/pr';
			n1			=	n1	+	_CR_n1;
			n2			=	n2	+	_CR_n2;
			Total		=	Total	+	_CR_Total;
			OUTPUT;
		END;
	ELSE
		DO;
			OUTPUT;
		END;

datalines;
cr 10 12 22 
pr 12 23 35
sd 23 24 47
ne 30 35 65
;
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-1601528987184.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50038iFCF5E42C35DFAF75/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1601528987184.png" alt="jimbarbour_0-1601528987184.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that's really all you need, please mark the solution; otherwise, please post more including more extensive data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 05:10:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-additional-record-by-adding-values-of-two/m-p/688109#M208982</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-01T05:10:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an additional record by adding values of two records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-additional-record-by-adding-values-of-two/m-p/688111#M208983</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want:
set have;
_n1 + n1;
_n2 + n2;
output;
if _n_ = 2
then do;
  val = "cr/pr";
  n1 = _n1;
  n2 = _n2;
  total = n1 + n2;
  output;
end;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 05:11:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-additional-record-by-adding-values-of-two/m-p/688111#M208983</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-01T05:11:36Z</dc:date>
    </item>
  </channel>
</rss>

