<?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: Make all obs in a group equal to the first observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Make-all-obs-in-a-group-equal-to-the-first-observation/m-p/805185#M317145</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;'s solution is the most efficacious if you really are trying to carry forward just one or two variables.&amp;nbsp; But if you have lots of variables then there is more coding overhead to generate.&amp;nbsp; In that case a simple DROP= list of variables to carry forward may be your best solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case, you might use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if 0 then set have;
  set have (drop=code);
  by name id;
  if first.id then set have point=_n_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just list the variables to be carried forward in the DROP= parameter.&amp;nbsp; Those variables will be read only when NAME or ID changes, and the IF condition is met.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note the "if 0 then set have;" statement is not neccessary.&amp;nbsp; I use it here, so that variable order is preserved.&amp;nbsp; Without it, the variables in the DROP list, which could be anywhere in the list of variables, will be output at the right end of the new data set.&lt;/P&gt;</description>
    <pubDate>Thu, 31 Mar 2022 02:00:21 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-03-31T02:00:21Z</dc:date>
    <item>
      <title>Make all obs in a group equal to the first observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-all-obs-in-a-group-equal-to-the-first-observation/m-p/805147#M317121</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;input&lt;BR /&gt;name : $1.&lt;BR /&gt;id : 8.&lt;BR /&gt;code : $8.&lt;BR /&gt;num_1 : 8.&lt;BR /&gt;num_2 : 8.&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;datalines;&lt;BR /&gt;A 10 12345678 1 0&lt;BR /&gt;A 10 09876543 0 1&lt;BR /&gt;A 34 23456789 1 1&lt;BR /&gt;B 9 88997700 1 0&lt;BR /&gt;B 9 88997700 0 0&lt;BR /&gt;B 9 88997700 0 1&lt;BR /&gt;C 28 11223344 1 1&lt;BR /&gt;C 28 34343434 1 0&lt;BR /&gt;C 28 67676767 0 0&lt;BR /&gt;C 30 78679870 1 0&lt;BR /&gt;C 30 78679870 0 1&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want:&lt;/P&gt;&lt;P&gt;A 10 12345678 1 0&lt;BR /&gt;A 10 12345678 0 1&lt;BR /&gt;A 34 23456789 1 1&lt;BR /&gt;B 9 88997700 1 0&lt;BR /&gt;B 9 88997700 0 0&lt;BR /&gt;B 9 88997700 0 1&lt;BR /&gt;C 28 11223344 1 1&lt;BR /&gt;C 28 11223344 1 0&lt;BR /&gt;C 28 11223344 0 0&lt;BR /&gt;C 30 78679870 1 0&lt;BR /&gt;C 30 78679870 0 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 21:03:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-all-obs-in-a-group-equal-to-the-first-observation/m-p/805147#M317121</guid>
      <dc:creator>noelle12</dc:creator>
      <dc:date>2022-03-30T21:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: Make all obs in a group equal to the first observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-all-obs-in-a-group-equal-to-the-first-observation/m-p/805148#M317122</link>
      <description>&lt;P&gt;Group by name and id&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 21:04:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-all-obs-in-a-group-equal-to-the-first-observation/m-p/805148#M317122</guid>
      <dc:creator>noelle12</dc:creator>
      <dc:date>2022-03-30T21:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: Make all obs in a group equal to the first observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-all-obs-in-a-group-equal-to-the-first-observation/m-p/805161#M317132</link>
      <description>&lt;P&gt;You might say exactly which variable(s) you want to set. Because your want does not make "all obs in a group equal" because there are still some variables not equal to the first obs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My try:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   by notsorted name id;
   length firstcode $ 8;
   retain firstcode;
   if first.id then firstcode=code;
   else code=firstcode;
   drop firstcode;
run;&lt;/PRE&gt;
&lt;P&gt;Assumes your data is at least grouped by the Name and Id values.&lt;/P&gt;
&lt;P&gt;Retain keeps a value of a variable across the data step boundary.&lt;/P&gt;
&lt;P&gt;The BY statement creates SAS automatic variables First. and Last. (do note the dot) that are 1/0 (true/false values) to tell you if a current observation is the first of a group. Assuming grouped by name then we use the ID value to test and set the retained variable to the first value. Otherwise assign the retained value to the other observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 22:22:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-all-obs-in-a-group-equal-to-the-first-observation/m-p/805161#M317132</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-30T22:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: Make all obs in a group equal to the first observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-all-obs-in-a-group-equal-to-the-first-observation/m-p/805185#M317145</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;'s solution is the most efficacious if you really are trying to carry forward just one or two variables.&amp;nbsp; But if you have lots of variables then there is more coding overhead to generate.&amp;nbsp; In that case a simple DROP= list of variables to carry forward may be your best solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case, you might use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if 0 then set have;
  set have (drop=code);
  by name id;
  if first.id then set have point=_n_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just list the variables to be carried forward in the DROP= parameter.&amp;nbsp; Those variables will be read only when NAME or ID changes, and the IF condition is met.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note the "if 0 then set have;" statement is not neccessary.&amp;nbsp; I use it here, so that variable order is preserved.&amp;nbsp; Without it, the variables in the DROP list, which could be anywhere in the list of variables, will be output at the right end of the new data set.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 02:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-all-obs-in-a-group-equal-to-the-first-observation/m-p/805185#M317145</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-03-31T02:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: Make all obs in a group equal to the first observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-all-obs-in-a-group-equal-to-the-first-observation/m-p/805206#M317159</link>
      <description>&lt;P&gt;My take:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have (rename=(code=_code));
by name id;
retain code;
if first.id then code = _code;
drop _code;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Mar 2022 06:51:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-all-obs-in-a-group-equal-to-the-first-observation/m-p/805206#M317159</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-31T06:51:07Z</dc:date>
    </item>
  </channel>
</rss>

