<?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: Combine observations with same name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combine-observations-with-same-name/m-p/364217#M86352</link>
    <description>&lt;P&gt;Please post test data in the form of a datastep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As such, not typing that out so this is just a guess (as your variable structure is not given and you are mixing character data - z x etc, with numeric missing value . &amp;nbsp;Also variables cannot be called 1 or 2, so I assume _1 or _2), I would retain the variables (but you could also do merge, and possibly even summing up the variables), also what happens when more than one appear?&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  array orig{6} _1--_6;
  array new{6} $1;
  by xxx yyy;
  retain new:;
  do i=1 to 6;
    if orig{i} ne "" then new{i}=orig{i};
  end;
  if last.yy then output;
run;&lt;/PRE&gt;</description>
    <pubDate>Mon, 05 Jun 2017 07:55:54 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-06-05T07:55:54Z</dc:date>
    <item>
      <title>Combine observations with same name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-observations-with-same-name/m-p/364215#M86350</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am relatively new to SAS programming. I have a data set that looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;xxx yyy 1 2 3 4 5 6&amp;nbsp;&lt;/P&gt;&lt;P&gt;a &amp;nbsp; &amp;nbsp;01 &amp;nbsp; . &amp;nbsp;. &amp;nbsp;z &amp;nbsp;. &amp;nbsp;. &amp;nbsp;.&lt;/P&gt;&lt;P&gt;a &amp;nbsp; &amp;nbsp;02 &amp;nbsp;&lt;SPAN&gt; . &amp;nbsp;x &amp;nbsp;. &amp;nbsp;. &amp;nbsp;. &amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;a &amp;nbsp; &amp;nbsp;02 &amp;nbsp;&lt;SPAN&gt; . &amp;nbsp;. . &amp;nbsp;. &amp;nbsp; c &amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;b &amp;nbsp; &amp;nbsp;01 &amp;nbsp;&lt;SPAN&gt;&amp;nbsp;v &amp;nbsp;. &amp;nbsp;. &amp;nbsp;. &amp;nbsp;. &amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;b &amp;nbsp; &amp;nbsp;01 &amp;nbsp;&lt;SPAN&gt;&amp;nbsp;. &amp;nbsp;b . &amp;nbsp;. &amp;nbsp;. &amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;b &amp;nbsp; &amp;nbsp;01 &amp;nbsp;&lt;SPAN&gt; . &amp;nbsp;. &amp;nbsp;n . &amp;nbsp; . &amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;c &amp;nbsp; &amp;nbsp;01 &amp;nbsp;&lt;SPAN&gt; . &amp;nbsp;. &amp;nbsp;. &amp;nbsp;m &amp;nbsp; . &amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And my question is how can I make the set to be with a single observation for the variable yyy and to look like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;xxx yyy 1 2 3 4 5 6&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;a &amp;nbsp; &amp;nbsp;01 &amp;nbsp; . &amp;nbsp;. &amp;nbsp;z &amp;nbsp;. &amp;nbsp;. &amp;nbsp;.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;a &amp;nbsp; &amp;nbsp;02 &amp;nbsp;&amp;nbsp;. x &amp;nbsp; . &amp;nbsp;. c &amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;b &amp;nbsp; &amp;nbsp;01 &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;v b &amp;nbsp;n &amp;nbsp;. &amp;nbsp;. &amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;c &amp;nbsp; &amp;nbsp;01 &amp;nbsp;&lt;SPAN&gt;. &amp;nbsp;. &amp;nbsp;. &amp;nbsp;m &amp;nbsp;. &amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jun 2017 06:31:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-observations-with-same-name/m-p/364215#M86350</guid>
      <dc:creator>wankata5</dc:creator>
      <dc:date>2017-06-05T06:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: Combine observations with same name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-observations-with-same-name/m-p/364217#M86352</link>
      <description>&lt;P&gt;Please post test data in the form of a datastep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As such, not typing that out so this is just a guess (as your variable structure is not given and you are mixing character data - z x etc, with numeric missing value . &amp;nbsp;Also variables cannot be called 1 or 2, so I assume _1 or _2), I would retain the variables (but you could also do merge, and possibly even summing up the variables), also what happens when more than one appear?&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  array orig{6} _1--_6;
  array new{6} $1;
  by xxx yyy;
  retain new:;
  do i=1 to 6;
    if orig{i} ne "" then new{i}=orig{i};
  end;
  if last.yy then output;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Jun 2017 07:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-observations-with-same-name/m-p/364217#M86352</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-05T07:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: Combine observations with same name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-observations-with-same-name/m-p/364227#M86353</link>
      <description>&lt;P&gt;So basically what I have is a data set like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data sales;&lt;BR /&gt;input Product $ Brand $ January February March April May June;&lt;BR /&gt;datalines;&lt;BR /&gt;TV SAMSUNG . . 1 . . .&lt;BR /&gt;TV SAMSUNG . . . 2 . .&lt;BR /&gt;TV SAMSUNG . . . . . 3&lt;BR /&gt;TV LG . . 2 . . .&lt;BR /&gt;TABLET IPAD . 1 . . . .&lt;BR /&gt;TABLET SAMSUNG . . . 5 . .&lt;BR /&gt;LAPTOP LENOVO 1 . . . . .&lt;BR /&gt;LAPTOP DELL . 2 . . . .&lt;BR /&gt;LAPTOP DELL . . 3 . . .&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And what I am looking for is a data set that looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data sales2;&lt;BR /&gt;input Product $ Brand $ January February March April May June;&lt;BR /&gt;datalines;&lt;BR /&gt;TV SAMSUNG . . 1 2 . 3&lt;BR /&gt;TV LG . . 2 . . .&lt;BR /&gt;TABLET IPAD . 1 . . . .&lt;BR /&gt;TABLET SAMSUNG . . . 5 . .&lt;BR /&gt;LAPTOP LENOVO 1 . . . . .&lt;BR /&gt;LAPTOP DELL . 2 3 . . .&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jun 2017 09:31:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-observations-with-same-name/m-p/364227#M86353</guid>
      <dc:creator>wankata5</dc:creator>
      <dc:date>2017-06-05T09:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: Combine observations with same name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-observations-with-same-name/m-p/364230#M86355</link>
      <description>&lt;P&gt;Well, a slight modification to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;'s solution here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/code-to-pull-forward-missing-values/m-p/345821#M79623" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/code-to-pull-forward-missing-values/m-p/345821#M79623&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this:&lt;/P&gt;
&lt;PRE&gt;data sales;
  input Product $ Brand $ January February March April May June;
datalines;
TV SAMSUNG . . 1 . . .
TV SAMSUNG . . . 2 . .
TV SAMSUNG . . . . . 3
TV LG . . 2 . . .
TABLET IPAD . 1 . . . .
TABLET SAMSUNG . . . 5 . .
LAPTOP LENOVO 1 . . . . .
LAPTOP DELL . 2 . . . .
LAPTOP DELL . . 3 . . .
;
run;

proc sort data=sales;
  by product brand;
run;

data locf;
  update sales(obs=0) sales;
  by product brand;
  if last.brand then output;
run;
&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Jun 2017 09:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-observations-with-same-name/m-p/364230#M86355</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-05T09:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: Combine observations with same name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-observations-with-same-name/m-p/364231#M86356</link>
      <description>&lt;P&gt;Thanks for your quick response.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works fine.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jun 2017 10:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-observations-with-same-name/m-p/364231#M86356</guid>
      <dc:creator>wankata5</dc:creator>
      <dc:date>2017-06-05T10:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: Combine observations with same name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-observations-with-same-name/m-p/364256#M86373</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;The default output for the UPDATE statement is LAST unique key, so you can leave off&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if last.brand then output;
&lt;/PRE&gt;
&lt;P&gt;It doesn't hurt but not needed.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jun 2017 12:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-observations-with-same-name/m-p/364256#M86373</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-06-05T12:37:42Z</dc:date>
    </item>
  </channel>
</rss>

