<?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: creating an observation combining different records? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/creating-an-observation-combining-different-records/m-p/162857#M263477</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Provide some test data and required output.&amp;nbsp; There are many logical methods of looking up observations which fit into many differing scenarios - hash tables, merge statements, have a set in a conditional branch, sub-querying in sql, lag() function, by group processing, arrays etc.&amp;nbsp; Say for instance your first options - combine 4,6,8 to 3rd observation - what does this actually mean.&amp;nbsp; The position of a row in a dataset is purely arbitrary, so if I sort that dataset maybe row 8 will be in position 3.&amp;nbsp; I wouldn't recommend to use arbitrary row number as a means to identify specific data.&lt;/P&gt;&lt;P&gt;If however row 4, 5, 6 contains a id variable for "sum" and row 3 has the id "total" then we could do:&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; idvar="not used"; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; idvar="not used"; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; idvar="total"; result=.; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; idvar="sum"; result=4; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; idvar="sum"; result=3; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; idvar="sum"; result=6; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table WANT as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select&amp;nbsp; IDVAR,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select SUM(RESULT) from WORK.HAVE where IDVAR="sum") as RESULT&lt;/P&gt;&lt;P&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; WORK.HAVE&lt;/P&gt;&lt;P&gt;&amp;nbsp; where&amp;nbsp;&amp;nbsp; IDVAR="total";&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Feb 2015 11:36:21 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2015-02-11T11:36:21Z</dc:date>
    <item>
      <title>creating an observation combining different records?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-an-observation-combining-different-records/m-p/162856#M263476</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'd like to understand how to combine obs from different records into a single observation in the output?For example, in sashelp.class or using some of your own input, can anybody demonstrate with a code how to accomplish the same?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. combine 4,6,and 8 to the 3rd observation?&lt;/P&gt;&lt;P&gt;2. combine 2nd obs, and last observation to 1st obs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What i really am after is i wanna understand how you look prev once you are past that iteration in the implied datastep loop. Examples i would appreciate is doing the sample in 1. multiple pass and 2. in single pass. Any kind of simple, medium and complex examples will really help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 11:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-an-observation-combining-different-records/m-p/162856#M263476</guid>
      <dc:creator>MarkWik</dc:creator>
      <dc:date>2015-02-11T11:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: creating an observation combining different records?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-an-observation-combining-different-records/m-p/162857#M263477</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Provide some test data and required output.&amp;nbsp; There are many logical methods of looking up observations which fit into many differing scenarios - hash tables, merge statements, have a set in a conditional branch, sub-querying in sql, lag() function, by group processing, arrays etc.&amp;nbsp; Say for instance your first options - combine 4,6,8 to 3rd observation - what does this actually mean.&amp;nbsp; The position of a row in a dataset is purely arbitrary, so if I sort that dataset maybe row 8 will be in position 3.&amp;nbsp; I wouldn't recommend to use arbitrary row number as a means to identify specific data.&lt;/P&gt;&lt;P&gt;If however row 4, 5, 6 contains a id variable for "sum" and row 3 has the id "total" then we could do:&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; idvar="not used"; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; idvar="not used"; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; idvar="total"; result=.; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; idvar="sum"; result=4; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; idvar="sum"; result=3; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; idvar="sum"; result=6; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table WANT as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select&amp;nbsp; IDVAR,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select SUM(RESULT) from WORK.HAVE where IDVAR="sum") as RESULT&lt;/P&gt;&lt;P&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; WORK.HAVE&lt;/P&gt;&lt;P&gt;&amp;nbsp; where&amp;nbsp;&amp;nbsp; IDVAR="total";&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 11:36:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-an-observation-combining-different-records/m-p/162857#M263477</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-02-11T11:36:21Z</dc:date>
    </item>
  </channel>
</rss>

