<?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 create new data set from arithmatical operation between observations in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/create-new-data-set-from-arithmatical-operation-between/m-p/58210#M16271</link>
    <description>Hi all,&lt;BR /&gt;
&lt;BR /&gt;
I am newbie to SAS with some experience with other computer programming language. I have problem as given below.&lt;BR /&gt;
&lt;BR /&gt;
Data A (have been sorted by Vehicle_Number Entry_Date):&lt;BR /&gt;
* Vehichle_Number&lt;BR /&gt;
* Entry_Date&lt;BR /&gt;
* Gate_ID&lt;BR /&gt;
&lt;BR /&gt;
From this data A, I want to have data B with:&lt;BR /&gt;
* Vehicle Number&lt;BR /&gt;
* Run_Time&lt;BR /&gt;
* Gate_From&lt;BR /&gt;
* Gate_To&lt;BR /&gt;
&lt;BR /&gt;
if Vehicle_Number (i) = Vehicle_Number (i+1) then&lt;BR /&gt;
do&lt;BR /&gt;
Vehicle_Number = Vehicle_Number&lt;BR /&gt;
Run_Time = Entry_Date (i+1) - Entry_Date (i) --&amp;gt; between two consecutive obs&lt;BR /&gt;
Gate_From = Gate_ID (i)&lt;BR /&gt;
Gate_To = Gate_ID (i+1)&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
I would like to translate that script into SAS programming language. How can I do that?&lt;BR /&gt;
&lt;BR /&gt;
Any advice will help.&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
    <pubDate>Thu, 30 Oct 2008 11:20:08 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-10-30T11:20:08Z</dc:date>
    <item>
      <title>create new data set from arithmatical operation between observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/create-new-data-set-from-arithmatical-operation-between/m-p/58210#M16271</link>
      <description>Hi all,&lt;BR /&gt;
&lt;BR /&gt;
I am newbie to SAS with some experience with other computer programming language. I have problem as given below.&lt;BR /&gt;
&lt;BR /&gt;
Data A (have been sorted by Vehicle_Number Entry_Date):&lt;BR /&gt;
* Vehichle_Number&lt;BR /&gt;
* Entry_Date&lt;BR /&gt;
* Gate_ID&lt;BR /&gt;
&lt;BR /&gt;
From this data A, I want to have data B with:&lt;BR /&gt;
* Vehicle Number&lt;BR /&gt;
* Run_Time&lt;BR /&gt;
* Gate_From&lt;BR /&gt;
* Gate_To&lt;BR /&gt;
&lt;BR /&gt;
if Vehicle_Number (i) = Vehicle_Number (i+1) then&lt;BR /&gt;
do&lt;BR /&gt;
Vehicle_Number = Vehicle_Number&lt;BR /&gt;
Run_Time = Entry_Date (i+1) - Entry_Date (i) --&amp;gt; between two consecutive obs&lt;BR /&gt;
Gate_From = Gate_ID (i)&lt;BR /&gt;
Gate_To = Gate_ID (i+1)&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
I would like to translate that script into SAS programming language. How can I do that?&lt;BR /&gt;
&lt;BR /&gt;
Any advice will help.&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Thu, 30 Oct 2008 11:20:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/create-new-data-set-from-arithmatical-operation-between/m-p/58210#M16271</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-30T11:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: create new data set from arithmatical operation between observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/create-new-data-set-from-arithmatical-operation-between/m-p/58211#M16272</link>
      <description>If you could supply some sample input data and desirable output, it would easier to help.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Thu, 30 Oct 2008 11:31:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/create-new-data-set-from-arithmatical-operation-between/m-p/58211#M16272</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2008-10-30T11:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: create new data set from arithmatical operation between observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/create-new-data-set-from-arithmatical-operation-between/m-p/58212#M16273</link>
      <description>Hi Linus,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your response.&lt;BR /&gt;
&lt;BR /&gt;
Below is the sample:&lt;BR /&gt;
&lt;BR /&gt;
Obs	Vehicle_Number	Entry_Date_Time	           Gate_ID&lt;BR /&gt;
1	SGG9274A	12-Jan-07 02:18:27 AM	A&lt;BR /&gt;
2	SSC7789N	16-May-07 04:45:58 PM	B&lt;BR /&gt;
3	SSC7989N	16-May-07 11:00:29 PM	B&lt;BR /&gt;
4	SSC7989N	05-Jul-07 06:33:38 PM	B&lt;BR /&gt;
5	SSC7989N	18-Jul-07 12:22:53 PM	C&lt;BR /&gt;
6	STM1209B	28-Feb-07 05:07:31 AM	A&lt;BR /&gt;
7	SVX3120C	                06-Sep-07 09:29:20 AM	A&lt;BR /&gt;
8	SVX3120C	                21-Sep-07 07:23:48 AM	C&lt;BR /&gt;
9	SVX3120C	                21-Sep-07 07:55:28 AM	C&lt;BR /&gt;
10	SVY3542N	09-Mar-07 03:06:24 PM	B&lt;BR /&gt;
11	SVY3542N	19-Mar-07 12:21:02 AM	B&lt;BR /&gt;
&lt;BR /&gt;
And here is the desirable output:&lt;BR /&gt;
&lt;BR /&gt;
Obs	Vehicle_Number	Run_Time	Gate_From       Gate_To&lt;BR /&gt;
1	SSC7789N	22471	       B	             B&lt;BR /&gt;
2	SSC7989N	1625589	       B	             B&lt;BR /&gt;
3	SSC7989N	1100955	       B	             C&lt;BR /&gt;
4	SVX3120C	                1288468	       A	             C&lt;BR /&gt;
5	SVX3120C	                1900	       C	             C&lt;BR /&gt;
6	SVY3542N	810878	       B	             B&lt;BR /&gt;
&lt;BR /&gt;
Run_Time is in seconds.&lt;BR /&gt;
&lt;BR /&gt;
Thanks.</description>
      <pubDate>Fri, 31 Oct 2008 01:46:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/create-new-data-set-from-arithmatical-operation-between/m-p/58212#M16273</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-31T01:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: create new data set from arithmatical operation between observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/create-new-data-set-from-arithmatical-operation-between/m-p/58213#M16274</link>
      <description>I think this is what you want but my results do not match your expectation exactly.  You do this by looking ahead by usually "I think" it is done by looking back.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
dm 'clear log; clear output;';&lt;BR /&gt;
data cars;&lt;BR /&gt;
   input&lt;BR /&gt;
Obs VehicleNumber :$8. EntryDateTime &amp;amp; datetime. GateID:$1.;&lt;BR /&gt;
   format E: dateampm19.;&lt;BR /&gt;
   drop obs;&lt;BR /&gt;
   cards;&lt;BR /&gt;
1 SGG9274A 12-Jan-07 02:18:27 AM  A&lt;BR /&gt;
2 SSC7789N 16-May-07 04:45:58 PM  B&lt;BR /&gt;
3 SSC7989N 16-May-07 11:00:29 PM  B&lt;BR /&gt;
4 SSC7989N 05-Jul-07 06:33:38 PM  B&lt;BR /&gt;
5 SSC7989N 18-Jul-07 12:22:53 PM  C&lt;BR /&gt;
6 STM1209B 28-Feb-07 05:07:31 AM  A&lt;BR /&gt;
7 SVX3120C 06-Sep-07 09:29:20 AM  A&lt;BR /&gt;
8 SVX3120C 21-Sep-07 07:23:48 AM  C&lt;BR /&gt;
9 SVX3120C 21-Sep-07 07:55:28 AM  C&lt;BR /&gt;
10 SVY3542N 09-Mar-07 03:06:24 PM  B&lt;BR /&gt;
11 SVY3542N 19-Mar-07 12:21:02 AM  B&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc sort;&lt;BR /&gt;
   by V: E:;&lt;BR /&gt;
   run;&lt;BR /&gt;
data cars;&lt;BR /&gt;
   do until(last.VehicleNumber);&lt;BR /&gt;
      set cars;&lt;BR /&gt;
      by v: E:;&lt;BR /&gt;
      FromGate = lag(GateID);&lt;BR /&gt;
      RunTime = dif(EntryDateTime);&lt;BR /&gt;
      ToGate  = GateID;&lt;BR /&gt;
      if first.VehicleNumber then call missing(of FromGate RunTime);&lt;BR /&gt;
      if not first.VehicleNumber then output;&lt;BR /&gt;
      end;&lt;BR /&gt;
   format runTime comma12.;&lt;BR /&gt;
   drop Entry: GateID;&lt;BR /&gt;
   drop &lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   by v:;&lt;BR /&gt;
   id v:;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;B&gt;&lt;BR /&gt;
Vehicle     From                     To&lt;BR /&gt;
 Number     Gate         RunTime    Gate&lt;BR /&gt;
&lt;BR /&gt;
SSC7989N     B         4,303,989     B&lt;BR /&gt;
             B         1,100,955     C&lt;BR /&gt;
&lt;BR /&gt;
SVX3120C     A         1,288,468     C&lt;BR /&gt;
             C             1,900     C&lt;BR /&gt;
&lt;BR /&gt;
SVY3542N     B           810,878     B&lt;BR /&gt;
&lt;B&gt;&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;/B&gt;&lt;/B&gt;</description>
      <pubDate>Fri, 31 Oct 2008 20:25:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/create-new-data-set-from-arithmatical-operation-between/m-p/58213#M16274</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2008-10-31T20:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: create new data set from arithmatical operation between observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/create-new-data-set-from-arithmatical-operation-between/m-p/58214#M16275</link>
      <description>Thanks for the idea. I learn something from your script.&lt;BR /&gt;
I will have SAS Base training this week and hope will find more.</description>
      <pubDate>Mon, 03 Nov 2008 01:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/create-new-data-set-from-arithmatical-operation-between/m-p/58214#M16275</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-11-03T01:15:27Z</dc:date>
    </item>
  </channel>
</rss>

