<?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 Comparing values of first observation with last observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-first-observation-with-last-observation/m-p/500331#M133224</link>
    <description>&lt;P&gt;Hello, I have a dataset that has 4 variables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OBS NAME BOARDING DESTINATION DATE&lt;/P&gt;&lt;P&gt;1 CHITRA DEHRADUN MUMBAI 04OCT2018&lt;BR /&gt;2 CHITRA MUMBAI HYDERABAD 01NOV2018&lt;BR /&gt;3 CHITRA HYDERABAD DELHI 30NOV2018&lt;BR /&gt;4 NANCY DELHI HYDERABAD 01OCT2018&lt;BR /&gt;5 NANCY HYDERABAD BANGALORE 02NOV2018&lt;BR /&gt;6 NANCY BANGALORE MUMBAI 30NOV2018&lt;BR /&gt;7 NANCY MUMBAI DELHI 31DEC2018&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want output to get split in two datasets(RETURN and NORETURN) .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RETURN dataset should have those observations whose Boarding and Destination stations are same like from above dataset Nancy started her journey from Delhi and returned to Delhi.&lt;/P&gt;&lt;P&gt;NAME BOARDING DESTINATION&lt;/P&gt;&lt;P&gt;NANCY DELHI DELHI&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NORETURN dataset should have those observations whose Boarding and Destination stations are not same like from above dataset Chitra started her Journey from Dehradun but she ended up in Delhi.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NAME BOARDING DESTINATION&lt;/P&gt;&lt;P&gt;CHITRA DEHRADUN DELHI&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried below code but not getting the output as I want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA TEST;&lt;BR /&gt;INPUT NAME $ BOARDING $ DESTINATION $ DATE$;&lt;BR /&gt;CARDS;&lt;BR /&gt;NANCY DELHI HYDERABAD 01OCT2018&lt;BR /&gt;NANCY HYDERABAD BANGALORE 2NOV2018&lt;BR /&gt;NANCY BANGALORE MUMBAI 30NOV2018&lt;BR /&gt;NANCY MUMBAI DELHI 31DEC2018&lt;BR /&gt;CHITRA DEHRADUN MUMBAI 04OCT2018&lt;BR /&gt;CHITRA MUMBAI HYDERABAD 01NOV2018&lt;BR /&gt;CHITRA HYDERABAD DELHI 30NOV2018&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;PROC SORT DATA = TEST; BY NAME;&lt;/P&gt;&lt;P&gt;DATA RETURN NORETURN;&lt;BR /&gt;SET TEST;&lt;BR /&gt;BY NAME;&lt;/P&gt;&lt;P&gt;IF FIRST.NAME THEN DO;&lt;BR /&gt;FIRST_BOARDING = BOARDING;&lt;BR /&gt;END;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;IF LAST.NAME THEN DO;&lt;BR /&gt;LAST_DESTINATION = DESTINATION;&lt;BR /&gt;END;&lt;/P&gt;&lt;P&gt;IF FIRST_BOARDING = LAST_DESTINATION THEN OUTPUT RETURN;&lt;BR /&gt;ELSE OUTPUT NORETURN;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone please suggest how can I get correct output?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
    <pubDate>Mon, 01 Oct 2018 12:38:11 GMT</pubDate>
    <dc:creator>NancyArora</dc:creator>
    <dc:date>2018-10-01T12:38:11Z</dc:date>
    <item>
      <title>Comparing values of first observation with last observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-first-observation-with-last-observation/m-p/500331#M133224</link>
      <description>&lt;P&gt;Hello, I have a dataset that has 4 variables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OBS NAME BOARDING DESTINATION DATE&lt;/P&gt;&lt;P&gt;1 CHITRA DEHRADUN MUMBAI 04OCT2018&lt;BR /&gt;2 CHITRA MUMBAI HYDERABAD 01NOV2018&lt;BR /&gt;3 CHITRA HYDERABAD DELHI 30NOV2018&lt;BR /&gt;4 NANCY DELHI HYDERABAD 01OCT2018&lt;BR /&gt;5 NANCY HYDERABAD BANGALORE 02NOV2018&lt;BR /&gt;6 NANCY BANGALORE MUMBAI 30NOV2018&lt;BR /&gt;7 NANCY MUMBAI DELHI 31DEC2018&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want output to get split in two datasets(RETURN and NORETURN) .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RETURN dataset should have those observations whose Boarding and Destination stations are same like from above dataset Nancy started her journey from Delhi and returned to Delhi.&lt;/P&gt;&lt;P&gt;NAME BOARDING DESTINATION&lt;/P&gt;&lt;P&gt;NANCY DELHI DELHI&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NORETURN dataset should have those observations whose Boarding and Destination stations are not same like from above dataset Chitra started her Journey from Dehradun but she ended up in Delhi.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NAME BOARDING DESTINATION&lt;/P&gt;&lt;P&gt;CHITRA DEHRADUN DELHI&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried below code but not getting the output as I want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA TEST;&lt;BR /&gt;INPUT NAME $ BOARDING $ DESTINATION $ DATE$;&lt;BR /&gt;CARDS;&lt;BR /&gt;NANCY DELHI HYDERABAD 01OCT2018&lt;BR /&gt;NANCY HYDERABAD BANGALORE 2NOV2018&lt;BR /&gt;NANCY BANGALORE MUMBAI 30NOV2018&lt;BR /&gt;NANCY MUMBAI DELHI 31DEC2018&lt;BR /&gt;CHITRA DEHRADUN MUMBAI 04OCT2018&lt;BR /&gt;CHITRA MUMBAI HYDERABAD 01NOV2018&lt;BR /&gt;CHITRA HYDERABAD DELHI 30NOV2018&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;PROC SORT DATA = TEST; BY NAME;&lt;/P&gt;&lt;P&gt;DATA RETURN NORETURN;&lt;BR /&gt;SET TEST;&lt;BR /&gt;BY NAME;&lt;/P&gt;&lt;P&gt;IF FIRST.NAME THEN DO;&lt;BR /&gt;FIRST_BOARDING = BOARDING;&lt;BR /&gt;END;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;IF LAST.NAME THEN DO;&lt;BR /&gt;LAST_DESTINATION = DESTINATION;&lt;BR /&gt;END;&lt;/P&gt;&lt;P&gt;IF FIRST_BOARDING = LAST_DESTINATION THEN OUTPUT RETURN;&lt;BR /&gt;ELSE OUTPUT NORETURN;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone please suggest how can I get correct output?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 12:38:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-first-observation-with-last-observation/m-p/500331#M133224</guid>
      <dc:creator>NancyArora</dc:creator>
      <dc:date>2018-10-01T12:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing values of first observation with last observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-first-observation-with-last-observation/m-p/500334#M133225</link>
      <description>&lt;P&gt;Please avoid coding in uppercase, its like being shouted at.&amp;nbsp; You could probably use hash table, but I would just go with simple two step approach, output last.record, merge that back on:&lt;/P&gt;
&lt;PRE&gt;data last;
  set test;
  by name;
  if last.name then output;
run;

data return noreturn;
  merge test last (keep=name destination rename=(destination=dest));
  by name;
  retain flag;
  flag=ifn(first.name and boarding=dest,1,0);
  if flag=1 then output;
run;&lt;/PRE&gt;
&lt;P&gt;Something like that (not tested).&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 12:44:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-first-observation-with-last-observation/m-p/500334#M133225</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-01T12:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing values of first observation with last observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-first-observation-with-last-observation/m-p/500356#M133241</link>
      <description>&lt;P&gt;You can do it with a single data step like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data return noreturn;
  do until (last.name);
    set test;
	by name notsorted;
	if first.name then 
	  Start=Boarding;
	end;
  end=destination;
  drop boarding destination;
  rename start=boarding end=destination;
  if start=end then
    output return;
  else
    output noreturn;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Oct 2018 13:41:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-values-of-first-observation-with-last-observation/m-p/500356#M133241</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-10-01T13:41:22Z</dc:date>
    </item>
  </channel>
</rss>

