<?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: Keeping first.variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keeping-first-variable/m-p/330406#M74115</link>
    <description>&lt;P&gt;The automatic variables created through dataset options (end=, nobs=, etc) or a by statement can never be kept in a dataset. You need to assign their values to "normal" variables, which will automatically appear in the output.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by group;
first_group = first.group;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 07 Feb 2017 08:48:18 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-02-07T08:48:18Z</dc:date>
    <item>
      <title>Keeping first.variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-first-variable/m-p/330403#M74114</link>
      <description>&lt;P&gt;Hi.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why am I not allowed to keep a first.variable (or last.variable) when using by group processing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I though that the first and last .variables were added to the PDV with an initial frop flag, which in my mind means that I kan also keep them if I want to?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that I can get around this issue by simply assigning the first.variable to a new variable as in the example below, but I am interested in the reason as to why the test1 dataset fails and the test2 dataset succeeds.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = sashelp.cars out=testdata;
   by cylinders;
run;

data test1;
   set testdata;
   by cylinders;
   keep first.cylinders; 
run;

data test2;
   set testdata;
   by cylinders;
   first = first.cylinders;
   keep first;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 08:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-first-variable/m-p/330403#M74114</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-02-07T08:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping first.variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-first-variable/m-p/330406#M74115</link>
      <description>&lt;P&gt;The automatic variables created through dataset options (end=, nobs=, etc) or a by statement can never be kept in a dataset. You need to assign their values to "normal" variables, which will automatically appear in the output.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by group;
first_group = first.group;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Feb 2017 08:48:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-first-variable/m-p/330406#M74115</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-07T08:48:18Z</dc:date>
    </item>
  </channel>
</rss>

