<?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: first. and last. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391826#M94191</link>
    <description>&lt;P&gt;i used it but still doesnt work&lt;/P&gt;</description>
    <pubDate>Wed, 30 Aug 2017 13:38:21 GMT</pubDate>
    <dc:creator>vraj1</dc:creator>
    <dc:date>2017-08-30T13:38:21Z</dc:date>
    <item>
      <title>first. and last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391820#M94187</link>
      <description>&lt;P&gt;I need to get for each usubjid i need the first&amp;nbsp;&lt;SPAN&gt;ECSTDTC(start date) and last&amp;nbsp;ECENDTC&amp;nbsp;(end date) so basically one record per usubjid.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=ec out=ec7; by usubjid ECSTDTC; run;&lt;BR /&gt;data ec1;&lt;BR /&gt;set ec7;&lt;BR /&gt;by usubjid ECSTDTC ECENDTC;&lt;BR /&gt;if First.ECSTDTC and last.ECENDTC then output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;can anyonew help me&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 13:30:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391820#M94187</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2017-08-30T13:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: first. and last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391822#M94188</link>
      <description>&lt;P&gt;If you want to use ECENDTC in the BY statement in your data step, then you should also sort by that variable in your PROC SORT.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 13:32:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391822#M94188</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-08-30T13:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: first. and last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391826#M94191</link>
      <description>&lt;P&gt;i used it but still doesnt work&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 13:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391826#M94191</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2017-08-30T13:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: first. and last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391827#M94192</link>
      <description>&lt;P&gt;How about:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc summary data=ec7 nway;&lt;/P&gt;
&lt;P&gt;class usubjid;&lt;/P&gt;
&lt;P&gt;var ecstdtc ecendtc;&lt;/P&gt;
&lt;P&gt;output out=want (keep=usubjid start_date end_date) min(ecstdtc)=start_date max(ecendtc)=end_date;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 13:39:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391827#M94192</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-08-30T13:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: first. and last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391829#M94193</link>
      <description>&lt;P&gt;unfortunately i cannot use proc summary as the dates are character dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 13:47:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391829#M94193</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2017-08-30T13:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: first. and last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391830#M94194</link>
      <description>&lt;P&gt;It's easy enough to convert character dates to numeric.&amp;nbsp; What format are they in?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would guess that they're in year-month-day form, or else sorting them couldn't help.&amp;nbsp; But one never knows.&amp;nbsp; Give a couple of examples.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 13:50:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391830#M94194</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-08-30T13:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: first. and last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391831#M94195</link>
      <description>&lt;P&gt;attaching test data&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 13:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391831#M94195</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2017-08-30T13:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: first. and last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391833#M94196</link>
      <description>&lt;P&gt;So these variables have both a date and a time.&amp;nbsp; Do you care about the time portion, or just the date portion?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 13:55:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391833#M94196</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-08-30T13:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: first. and last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391834#M94197</link>
      <description>&lt;P&gt;can usubjid be used in that code and take first and last observation? as i need time as well to calculate duration later&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 13:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391834#M94197</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2017-08-30T13:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: first. and last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391838#M94198</link>
      <description>&lt;P&gt;It would definitely work (but might be overkill) to process each variable separately:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by usubjid ecstdtc;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;data start;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by usubjid ecstdtc;&lt;/P&gt;
&lt;P&gt;if first.usubjid;&lt;/P&gt;
&lt;P&gt;keep usubjid ecstdtc;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by usubjid ecendtc;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;data finish;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by usubjid ecendtc;&lt;/P&gt;
&lt;P&gt;if last.usubjid;&lt;/P&gt;
&lt;P&gt;keep usubjid ecendtc;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you can see the handwriting on the wall here ... your life will be a lot simpler down the road if you start out by converting&amp;nbsp; those character variables to numeric DATETIMEs, since SAS is built to handle those easily.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 14:02:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391838#M94198</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-08-30T14:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: first. and last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391848#M94202</link>
      <description>&lt;P&gt;That is not how the by variables work. They indicate whether the current record is the first or the last for the group defined by the by variable. &amp;nbsp;So FIRST.&lt;SPAN&gt;ECSTDTC and LAST.ECENDTC could only be true if there is only one record for that value of ECSTDTC within that value of USUBJID.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If your data it properly sorted and has no missing values then you want.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ec1;
  set ec7;
  by usubjid ;
  retain first_start ;
  if first.usubjid then first_start=ECSTDTC;
  if last.usubjid ;
  last_stop = ECENDTC;
  keep usubjid first_start last_stop ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;If you have missing values then you will need to add more logic and also retain the variable you use to store the last end date.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 14:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/391848#M94202</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-08-30T14:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: first. and last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/392114#M94290</link>
      <description>&lt;P&gt;Thanks a lot Tom.&lt;/P&gt;
&lt;P&gt;Can the new date format be converted to date9(characcter) in the same data step?&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 07:11:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-and-last/m-p/392114#M94290</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2017-08-31T07:11:15Z</dc:date>
    </item>
  </channel>
</rss>

