<?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 Data Step: by two groups (First.id and first.department) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-by-two-groups-First-id-and-first-department/m-p/503347#M134487</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to define a minimum regarding ID as main variable (which works).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; MIN_DATE&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; 01/02/2015&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc Sort Data=have;&lt;BR /&gt;by ID YEAR MONTH;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data MIN;&lt;BR /&gt;set have;&lt;BR /&gt;by ID;&lt;BR /&gt;MIN_YEAR=YEAR;&lt;BR /&gt;MIN_MONTH=MONTH;&lt;BR /&gt;MIN_DATE=MDY(MIN_MONAT,1,MIN_JAHR);&lt;BR /&gt;format MIN_DATE ddmmyy10.;&lt;BR /&gt;If First.ID then output;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now i want to define a minimum for ID as well as for another subvariable (X) and this should look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp;&amp;nbsp; X&amp;nbsp; MIN_DATE&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; a&amp;nbsp; 01/02/2015&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; b&amp;nbsp; 01/04/2016&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i tried this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc Sort Data=have;&lt;BR /&gt;by ID X YEAR MONTH;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data MIN;&lt;BR /&gt;set have;&lt;BR /&gt;by ID &lt;STRONG&gt;X&lt;/STRONG&gt;;&lt;BR /&gt;MIN_YEAR=YEAR;&lt;BR /&gt;MIN_MONTH=MONTH;&lt;BR /&gt;MIN_DATE=MDY(MIN_MONAT,1,MIN_JAHR);&lt;BR /&gt;format MIN_DATE ddmmyy10.;&lt;BR /&gt;If First.ID &lt;STRONG&gt;AND FIRST.X&lt;/STRONG&gt; then output;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But my subvariable X is not considered.....its just the same as above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you help me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
    <pubDate>Thu, 11 Oct 2018 09:59:03 GMT</pubDate>
    <dc:creator>Dynamike</dc:creator>
    <dc:date>2018-10-11T09:59:03Z</dc:date>
    <item>
      <title>Data Step: by two groups (First.id and first.department)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-by-two-groups-First-id-and-first-department/m-p/503347#M134487</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to define a minimum regarding ID as main variable (which works).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; MIN_DATE&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; 01/02/2015&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc Sort Data=have;&lt;BR /&gt;by ID YEAR MONTH;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data MIN;&lt;BR /&gt;set have;&lt;BR /&gt;by ID;&lt;BR /&gt;MIN_YEAR=YEAR;&lt;BR /&gt;MIN_MONTH=MONTH;&lt;BR /&gt;MIN_DATE=MDY(MIN_MONAT,1,MIN_JAHR);&lt;BR /&gt;format MIN_DATE ddmmyy10.;&lt;BR /&gt;If First.ID then output;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now i want to define a minimum for ID as well as for another subvariable (X) and this should look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp;&amp;nbsp; X&amp;nbsp; MIN_DATE&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; a&amp;nbsp; 01/02/2015&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; b&amp;nbsp; 01/04/2016&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i tried this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc Sort Data=have;&lt;BR /&gt;by ID X YEAR MONTH;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data MIN;&lt;BR /&gt;set have;&lt;BR /&gt;by ID &lt;STRONG&gt;X&lt;/STRONG&gt;;&lt;BR /&gt;MIN_YEAR=YEAR;&lt;BR /&gt;MIN_MONTH=MONTH;&lt;BR /&gt;MIN_DATE=MDY(MIN_MONAT,1,MIN_JAHR);&lt;BR /&gt;format MIN_DATE ddmmyy10.;&lt;BR /&gt;If First.ID &lt;STRONG&gt;AND FIRST.X&lt;/STRONG&gt; then output;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But my subvariable X is not considered.....its just the same as above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you help me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 09:59:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step-by-two-groups-First-id-and-first-department/m-p/503347#M134487</guid>
      <dc:creator>Dynamike</dc:creator>
      <dc:date>2018-10-11T09:59:03Z</dc:date>
    </item>
    <item>
      <title>Re: Data Step: by two groups (First.id and first.department)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-by-two-groups-First-id-and-first-department/m-p/503348#M134488</link>
      <description>&lt;P&gt;Your code will not run, but throw an ERROR because versid is not in the by statement, therefore first.versid does not exist.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 09:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step-by-two-groups-First-id-and-first-department/m-p/503348#M134488</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-11T09:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Data Step: by two groups (First.id and first.department)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-by-two-groups-First-id-and-first-department/m-p/503354#M134491</link>
      <description>&lt;P&gt;Sorry my fault: VERSID is the same as ID.&lt;/P&gt;&lt;P&gt;I have corrected it in the original post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your advice!&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 09:59:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step-by-two-groups-First-id-and-first-department/m-p/503354#M134491</guid>
      <dc:creator>Dynamike</dc:creator>
      <dc:date>2018-10-11T09:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: Data Step: by two groups (First.id and first.department)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-by-two-groups-First-id-and-first-department/m-p/503357#M134492</link>
      <description>&lt;P&gt;Your problem is the use of&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;first.id and first.x&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as that will only be true for the first occurence of an id.&lt;/P&gt;
&lt;P&gt;A reduced subsetting if will work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id x $ year month;
cards;
1 a 2018 1
1 a 2018 3
1 a 2018 2
1 b 2017 12
1 b 2017 3
;
run;

Proc Sort Data=have;
by ID X YEAR MONTH;
run;

Data MIN;
set have;
by ID X;
MIN_YEAR=YEAR;
MIN_MONTH=MONTH;
MIN_DATE=MDY(MIN_MONAT,1,MIN_JAHR);
format MIN_DATE ddmmyy10.;
If FIRST.X;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Oct 2018 10:11:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step-by-two-groups-First-id-and-first-department/m-p/503357#M134492</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-11T10:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: Data Step: by two groups (First.id and first.department)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-by-two-groups-First-id-and-first-department/m-p/503359#M134493</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;... and make sure that you use consistent variable names (see MIN_YEAR vs. MIN_JAHR). To improve efficiency, you could move the three assignment statements &lt;FONT face="courier new,courier"&gt;MIN_&lt;/FONT&gt;...&lt;FONT face="courier new,courier"&gt;=&lt;/FONT&gt;...&amp;nbsp;together with the OUTPUT statement into a DO-END block:&lt;/P&gt;
&lt;PRE&gt;if first.x then do; ...; end;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;or, even simpler, put "&lt;FONT face="courier new,courier"&gt;if first.x;&lt;/FONT&gt;" directly after the BY statement.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 10:20:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step-by-two-groups-First-id-and-first-department/m-p/503359#M134493</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-10-11T10:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: Data Step: by two groups (First.id and first.department)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-by-two-groups-First-id-and-first-department/m-p/503374#M134496</link>
      <description>&lt;P&gt;If you want to get one observation per ID,X group then just reference FIRST.X.&amp;nbsp; If you include FIRST.ID you are looking for only one observation per ID group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If you do include FIRST.ID there is no need to also include FIRST.X.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;When you are on the first &lt;SPAN&gt;observation&amp;nbsp;&lt;/SPAN&gt;for the current ID group you are by definition on the first &lt;SPAN&gt;observation&amp;nbsp;for the current X group.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 12:41:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step-by-two-groups-First-id-and-first-department/m-p/503374#M134496</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-11T12:41:35Z</dc:date>
    </item>
  </channel>
</rss>

