<?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: How to match observations in SAS and compute results basis the match results in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-match-observations-in-SAS-and-compute-results-basis-the/m-p/495199#M130652</link>
    <description>&lt;P&gt;I made the code in SAS for reference along with data lines.&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a column within the datalines which shows the expected desired output also. I want to perform this operation for multiple numeric columns (as shown in Desired output)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data s;&lt;BR /&gt;input A $ Type $ Date mmddyy10. time time. d desired_op;&lt;BR /&gt;format date mmddyy10. time time.;&lt;BR /&gt;datalines;&lt;BR /&gt;Test ANC 9/13/2018 8:15:00 1 2&lt;BR /&gt;Test ANC 9/13/2018 8:15:00 1 1&lt;BR /&gt;Test ANC 9/13/2018 8:45:00 2 5&lt;BR /&gt;Test ANC 9/13/2018 8:45:00 3 3&lt;BR /&gt;Test DFL 9/13/2018 9:15:00 4 9&lt;BR /&gt;Test DFL 9/13/2018 9:15:00 5 5&lt;BR /&gt;Test DFL 9/13/2018 9:45:00 6 13&lt;BR /&gt;Test DFL 9/13/2018 9:45:00 7 7&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;set s;&lt;BR /&gt;conc = cats(type, date, time);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data =test out = test1;&lt;BR /&gt;by conc;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data test2;&lt;BR /&gt;set test1;&lt;BR /&gt;by conc;&lt;BR /&gt;if first.conc = 1 then d = d+d;&lt;BR /&gt;else d = d;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Sep 2018 08:39:05 GMT</pubDate>
    <dc:creator>sahilkh18</dc:creator>
    <dc:date>2018-09-13T08:39:05Z</dc:date>
    <item>
      <title>How to match observations in SAS and compute results basis the match results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-match-observations-in-SAS-and-compute-results-basis-the/m-p/495181#M130640</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I have a dataset with a lot of observations in it. I want to match the type, date and time, and if everything is a match, then sum up the first occurrence of each column D, E and F.&lt;/P&gt;&lt;P&gt;I have attached the sample data and the desired output. I need to match the data in row # 2 and row # 3 (columns B, C and D) and basis that sum up the values in the remaining columns in a cumulative manner (desired output shown). I tried using the first.variable, but it did not give me the desired output. Please help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What i tried doing was this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data s;&lt;/P&gt;&lt;P&gt;set test;&lt;/P&gt;&lt;P&gt;conc = cats(type, date, time); 'this way i can get the final value to match'&lt;/P&gt;&lt;P&gt;if first.conc = 1 then d = d+1;&lt;/P&gt;&lt;P&gt;else d=d;&lt;/P&gt;&lt;P&gt;if first.conc = 1 then e = e+1;&lt;/P&gt;&lt;P&gt;else e=e;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It does not give me the desired output i need.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 07:36:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-match-observations-in-SAS-and-compute-results-basis-the/m-p/495181#M130640</guid>
      <dc:creator>sahilkh18</dc:creator>
      <dc:date>2018-09-13T07:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to match observations in SAS and compute results basis the match results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-match-observations-in-SAS-and-compute-results-basis-the/m-p/495184#M130642</link>
      <description>&lt;P&gt;Please post your example data in the form of a datastep.&lt;BR /&gt;&lt;BR /&gt;In order to use first.var, your dataset has to be sorted by var. First create your conc variable and sort your dataset by conc then you can modify d and e variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit :don't forget to add a by statement in your data step :&lt;/P&gt;
&lt;P&gt;by conc;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 07:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-match-observations-in-SAS-and-compute-results-basis-the/m-p/495184#M130642</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-09-13T07:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to match observations in SAS and compute results basis the match results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-match-observations-in-SAS-and-compute-results-basis-the/m-p/495185#M130643</link>
      <description>&lt;P&gt;Please post the data as data-step using datalines statement so we can see the data in the same way your sas-session sees it. Excel-files are not suitable for transporting data.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 07:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-match-observations-in-SAS-and-compute-results-basis-the/m-p/495185#M130643</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-09-13T07:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to match observations in SAS and compute results basis the match results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-match-observations-in-SAS-and-compute-results-basis-the/m-p/495199#M130652</link>
      <description>&lt;P&gt;I made the code in SAS for reference along with data lines.&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a column within the datalines which shows the expected desired output also. I want to perform this operation for multiple numeric columns (as shown in Desired output)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data s;&lt;BR /&gt;input A $ Type $ Date mmddyy10. time time. d desired_op;&lt;BR /&gt;format date mmddyy10. time time.;&lt;BR /&gt;datalines;&lt;BR /&gt;Test ANC 9/13/2018 8:15:00 1 2&lt;BR /&gt;Test ANC 9/13/2018 8:15:00 1 1&lt;BR /&gt;Test ANC 9/13/2018 8:45:00 2 5&lt;BR /&gt;Test ANC 9/13/2018 8:45:00 3 3&lt;BR /&gt;Test DFL 9/13/2018 9:15:00 4 9&lt;BR /&gt;Test DFL 9/13/2018 9:15:00 5 5&lt;BR /&gt;Test DFL 9/13/2018 9:45:00 6 13&lt;BR /&gt;Test DFL 9/13/2018 9:45:00 7 7&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;set s;&lt;BR /&gt;conc = cats(type, date, time);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data =test out = test1;&lt;BR /&gt;by conc;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data test2;&lt;BR /&gt;set test1;&lt;BR /&gt;by conc;&lt;BR /&gt;if first.conc = 1 then d = d+d;&lt;BR /&gt;else d = d;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 08:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-match-observations-in-SAS-and-compute-results-basis-the/m-p/495199#M130652</guid>
      <dc:creator>sahilkh18</dc:creator>
      <dc:date>2018-09-13T08:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to match observations in SAS and compute results basis the match results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-match-observations-in-SAS-and-compute-results-basis-the/m-p/495200#M130653</link>
      <description>I made the code in SAS for reference along with data lines.&lt;BR /&gt;&lt;BR /&gt;There is a column within the datalines which shows the expected desired output also. I want to perform this operation for multiple numeric columns (as shown in Desired output)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data s;&lt;BR /&gt;input A $ Type $ Date mmddyy10. time time. d desired_op;&lt;BR /&gt;format date mmddyy10. time time.;&lt;BR /&gt;datalines;&lt;BR /&gt;Test ANC 9/13/2018 8:15:00 1 2&lt;BR /&gt;Test ANC 9/13/2018 8:15:00 1 1&lt;BR /&gt;Test ANC 9/13/2018 8:45:00 2 5&lt;BR /&gt;Test ANC 9/13/2018 8:45:00 3 3&lt;BR /&gt;Test DFL 9/13/2018 9:15:00 4 9&lt;BR /&gt;Test DFL 9/13/2018 9:15:00 5 5&lt;BR /&gt;Test DFL 9/13/2018 9:45:00 6 13&lt;BR /&gt;Test DFL 9/13/2018 9:45:00 7 7&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data test;&lt;BR /&gt;set s;&lt;BR /&gt;conc = cats(type, date, time);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sort data =test out = test1;&lt;BR /&gt;by conc;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data test2;&lt;BR /&gt;set test1;&lt;BR /&gt;by conc;&lt;BR /&gt;if first.conc = 1 then d = d+d;&lt;BR /&gt;else d = d;&lt;BR /&gt;run;</description>
      <pubDate>Thu, 13 Sep 2018 08:40:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-match-observations-in-SAS-and-compute-results-basis-the/m-p/495200#M130653</guid>
      <dc:creator>sahilkh18</dc:creator>
      <dc:date>2018-09-13T08:40:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to match observations in SAS and compute results basis the match results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-match-observations-in-SAS-and-compute-results-basis-the/m-p/495228#M130659</link>
      <description>&lt;P&gt;Your program doesn't really sum up anything.&amp;nbsp; To do that, you will need to create a new variable.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if first.conc then total_d + d;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That change might be enough to get the result you are looking for.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 11:24:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-match-observations-in-SAS-and-compute-results-basis-the/m-p/495228#M130659</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-13T11:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to match observations in SAS and compute results basis the match results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-match-observations-in-SAS-and-compute-results-basis-the/m-p/495354#M130719</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/233038"&gt;@sahilkh18&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I made the code in SAS for reference along with data lines.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a column within the datalines which shows the expected desired output also. I want to perform this operation for multiple numeric columns (as shown in Desired output)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data s;&lt;BR /&gt;input A $ Type $ Date mmddyy10. time time. d desired_op;&lt;BR /&gt;format date mmddyy10. time time.;&lt;BR /&gt;datalines;&lt;BR /&gt;Test ANC 9/13/2018 8:15:00 1 2&lt;BR /&gt;Test ANC 9/13/2018 8:15:00 1 1&lt;BR /&gt;Test ANC 9/13/2018 8:45:00 2 5&lt;BR /&gt;Test ANC 9/13/2018 8:45:00 3 3&lt;BR /&gt;Test DFL 9/13/2018 9:15:00 4 9&lt;BR /&gt;Test DFL 9/13/2018 9:15:00 5 5&lt;BR /&gt;Test DFL 9/13/2018 9:45:00 6 13&lt;BR /&gt;Test DFL 9/13/2018 9:45:00 7 7&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;set s;&lt;BR /&gt;conc = cats(type, date, time);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data =test out = test1;&lt;BR /&gt;by conc;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data test2;&lt;BR /&gt;set test1;&lt;BR /&gt;by conc;&lt;BR /&gt;if first.conc = 1 then d = d+d;&lt;BR /&gt;else d = d;&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This works for the example data. No need to add variables. It should work if you have more than 2 rows for Type/date/time combinations.&lt;/P&gt;
&lt;PRE&gt;data s;
   input A $ Type $ Date mmddyy10. time time. d desired_op;
   format date mmddyy10. time time.;
datalines;
Test ANC 9/13/2018 8:15:00 1 2
Test ANC 9/13/2018 8:15:00 1 1
Test ANC 9/13/2018 8:45:00 2 5
Test ANC 9/13/2018 8:45:00 3 3
Test DFL 9/13/2018 9:15:00 4 9
Test DFL 9/13/2018 9:15:00 5 5
Test DFL 9/13/2018 9:45:00 6 13
Test DFL 9/13/2018 9:45:00 7 7
;
run;
proc sort data=s;
 by type date time;
run;


proc summary data=s nway;
   class type date time;
   var d;
   output out=s_sum (drop= _:) sum=;
run;

data test2;
   merge s
         s_sum
   ;
 by type date time;
run;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Sep 2018 15:17:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-match-observations-in-SAS-and-compute-results-basis-the/m-p/495354#M130719</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-09-13T15:17:24Z</dc:date>
    </item>
  </channel>
</rss>

