<?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: Need help with first. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-first/m-p/986999#M380017</link>
    <description>&lt;P&gt;What do you mean by not working?&amp;nbsp; Does your new dataset have zero observations?&amp;nbsp; Is that what you expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your data step will only have observations when there are observations that have equal values for all three of those variables since the one you referenced SUBJID is the last of the three in the BY statement.&amp;nbsp; And the first observation in those BY groups will not be output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you wanted a dataset that has only one observation per BY group you should use one of these:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if first.subjid;
if last.subjid;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you wanted a dataset that has all of the duplicate observations for the BY groups that have duplicates then you should use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if not (first.subjid and last.subjid);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which will remove the BY groups that only have one observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you are confused about what FIRST. means when there are multiple BY variables?&amp;nbsp; FIRST.SUBJID is true when any of the three variables change value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 29 Apr 2026 23:40:05 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2026-04-29T23:40:05Z</dc:date>
    <item>
      <title>Need help with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-first/m-p/986997#M380015</link>
      <description>&lt;P&gt;Hello, the result of this code is giving me 0 observations.&amp;nbsp; The data does have duplicate rows per subjid so I expect there to be resulting rows.&amp;nbsp; The data is sorted correctly.&amp;nbsp; When I do "if first.subjid" I get the right number of rows.&amp;nbsp; It's just the "not" part that doesn't seem to be working. Can anyone see what I am doing wrong?&amp;nbsp; I'm so frustrated haha&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc sort data = ae_06c; by studyid site subjid; run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;data ae_06d; *has a 1;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;set ae_06c ;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;by studyid site subjid;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if not first.subjid ;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2026 20:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-first/m-p/986997#M380015</guid>
      <dc:creator>cbig</dc:creator>
      <dc:date>2026-04-29T20:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-first/m-p/986998#M380016</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/481405"&gt;@cbig&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello, the result of this code is giving me 0 observations.&amp;nbsp; The data does have duplicate rows per subjid so I expect there to be resulting rows.&amp;nbsp; The data is sorted correctly.&amp;nbsp; When I do "if first.subjid" I get the right number of rows.&amp;nbsp; It's just the "not" part that doesn't seem to be working. Can anyone see what I am doing wrong?&amp;nbsp; I'm so frustrated haha&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc sort data = ae_06c; by studyid site subjid; run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;data ae_06d; *has a 1;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;set ae_06c ;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;by studyid site subjid;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;if not first.subjid ;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hello,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/481405"&gt;@cbig&lt;/a&gt;&amp;nbsp;! For this post and really for all your future posts, please provide us with some sample data that illustrates the problem. That would be very helpful and would likely result in you getting faster and more correct answers. Here are &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt; of how to provide us with sample data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without an example data set, I cannot figure out why your code doesn't work. It seems like it should work, however the main reason I can think of why it doesn't work is that your data isn't really what you said it was. So providing an example data set that illustrates the problem would straighten all of this out.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Also, there are possibly important clues in the log. When your code is not behaving, please &lt;STRONG&gt;ALWAYS&lt;/STRONG&gt; provide us with a copy of the log. Please copy the log for this DATA step (not just the possible ERRORs and WARNINGs but the entire log for this DATA step)and paste it into the Window that appears when you click on the &amp;lt;/&amp;gt; icon.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1663012019648.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75161i0E71B1489A6C9839/image-size/large?v=v2&amp;amp;px=999" role="button" title="PaigeMiller_0-1663012019648.png" alt="PaigeMiller_0-1663012019648.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2026 22:53:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-first/m-p/986998#M380016</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2026-04-29T22:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-first/m-p/986999#M380017</link>
      <description>&lt;P&gt;What do you mean by not working?&amp;nbsp; Does your new dataset have zero observations?&amp;nbsp; Is that what you expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your data step will only have observations when there are observations that have equal values for all three of those variables since the one you referenced SUBJID is the last of the three in the BY statement.&amp;nbsp; And the first observation in those BY groups will not be output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you wanted a dataset that has only one observation per BY group you should use one of these:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if first.subjid;
if last.subjid;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you wanted a dataset that has all of the duplicate observations for the BY groups that have duplicates then you should use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if not (first.subjid and last.subjid);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which will remove the BY groups that only have one observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you are confused about what FIRST. means when there are multiple BY variables?&amp;nbsp; FIRST.SUBJID is true when any of the three variables change value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2026 23:40:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-first/m-p/986999#M380017</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-04-29T23:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-first/m-p/987003#M380018</link>
      <description>&lt;P&gt;It is not clear what you expect to see in the resulting dataset. Here's an example using sashelp.class, sorted by sex and age to display what "not first.variable means:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=work.class_sorted;
    by Sex Age;
run;

data work.selection;
    set work.class_sorted;
    by Sex Age;
    
    not_first = not first.Age;
    
run;
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Apr 2026 05:12:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-first/m-p/987003#M380018</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2026-04-30T05:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-first/m-p/987004#M380019</link>
      <description>&lt;P&gt;Just FYI ...&lt;BR /&gt;&lt;BR /&gt;Two PROC SORT options that you might find useful:&lt;/P&gt;
&lt;DIV class="xisDoc-refProc"&gt;
&lt;DIV class="xisDoc-refBlock"&gt;
&lt;DIV class="xisDoc-syntax"&gt;
&lt;DIV class="xisDoc-generatedOptionCategoryList"&gt;
&lt;UL&gt;
&lt;LI class="xisDoc-option"&gt;&lt;FONT size="4"&gt;NODUPKEY : deletes observations with duplicate BY values.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class="xisDoc-option"&gt;&lt;FONT size="4"&gt;DUPOUT =&amp;nbsp;&lt;EM&gt;SAS_data_set&lt;/EM&gt; :&amp;nbsp;&lt;SPAN&gt;specifies the output data set to which duplicate observations are written.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;BR,&lt;BR /&gt;Koen&lt;/P&gt;</description>
      <pubDate>Thu, 30 Apr 2026 07:34:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-first/m-p/987004#M380019</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2026-04-30T07:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-first/m-p/987005#M380020</link>
      <description>&lt;P&gt;If all your combinations of&lt;/P&gt;
&lt;PRE&gt;studyid site subjid&lt;/PRE&gt;
&lt;P&gt;are unique, then&lt;/P&gt;
&lt;PRE&gt;first.subjid&lt;/PRE&gt;
&lt;P&gt;will always be true, and the whole condition always false. Your empty result dataset proves that all combinations are unique and you have no duplicates.&lt;/P&gt;
&lt;P&gt;Multiple entries for a given subjid are obviously contained in different studies/sites.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Apr 2026 08:30:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-first/m-p/987005#M380020</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2026-04-30T08:30:04Z</dc:date>
    </item>
  </channel>
</rss>

