<?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 from one Variable to another Variable? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147815#M39116</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or you could use this after the initial read in:&lt;/P&gt;&lt;P&gt;data have2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array mon (4) m1-m4;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array moni (3) mi1-mi3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i = 1 to 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if mon(i) ~=. and mon(i+1)~=. then moni(i) = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else moni(i) = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select distinct sum(mi1) as mi1, sum(mi2) as mi2, sum(mi3) as mi3, sum(case when m2~=. and m1 ~=. then 1 else 0 end) as m2mi1,&lt;/P&gt;&lt;P&gt;sum(case when m3~=. and (m1~=. or m2~=.) then 1 else 0 end) as m3mi12, sum(case when m4 ~=. and (m1~=. or m2 ~=. or m3 ~=.) then 1 else 0 end) as m4mi123&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from have2;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 15 May 2014 15:53:56 GMT</pubDate>
    <dc:creator>overmar</dc:creator>
    <dc:date>2014-05-15T15:53:56Z</dc:date>
    <item>
      <title>How to Match Observations from one Variable to another Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147806#M39107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have recently migrated over from STATA. I have a set of panel data and want to observe the change in observations for a specific variable from one period to the next. I initially used the compare procedure; however, this does not work if the two variables are not sorted the same, etc. How should I go about comparing these variables?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 May 2014 19:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147806#M39107</guid>
      <dc:creator>brettmullga</dc:creator>
      <dc:date>2014-05-06T19:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to Match Observations from one Variable to another Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147807#M39108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What does your data look like? What type of output do you expect?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 May 2014 20:05:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147807#M39108</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-05-06T20:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to Match Observations from one Variable to another Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147808#M39109</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The variable I'm concerned is a list of participants. I have monthly data that goes back a decade or so. From one month to the next, I want to see how many drop out and how many new participants enter. I'm currently getting descriptive statistics as a part of a larger project. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 May 2014 20:10:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147808#M39109</guid>
      <dc:creator>brettmullga</dc:creator>
      <dc:date>2014-05-06T20:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to Match Observations from one Variable to another Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147809#M39110</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok...but how do your rows and columns look like. Do you have one record per participant and different variables for different time points or one record per participant per time?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's really helpful to post some sample data and expected sample output.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 May 2014 20:15:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147809#M39110</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-05-06T20:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to Match Observations from one Variable to another Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147810#M39111</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, Reeza. I was confused about what I was asking for.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Participant&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;Month1&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Month2&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Month3&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Month4&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;8&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;.&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;.&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;.&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;3&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;3&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;4&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;5&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;.&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;4&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;.&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;.&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to be able to count the number of participants in each month and the change in participants each month. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my first attempt at this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select count(*) as Total,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(month1) as Month_1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(month2) as Month_2,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(month3) as Month_3,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(month4) as Month_4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from work.charity;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;Total&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Month_1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Month_2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Month_3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Month_4&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This works to count individual columns but not the intersection of two months. The intersection will illustrate how many from one month continued on to the next month. Is it possible to specify this within the count statement?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 May 2014 19:28:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147810#M39111</guid>
      <dc:creator>brettmullga</dc:creator>
      <dc:date>2014-05-14T19:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to Match Observations from one Variable to another Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147811#M39112</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What do you want the output to look like.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 May 2014 19:49:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147811#M39112</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-05-14T19:49:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to Match Observations from one Variable to another Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147812#M39113</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Output 1:&lt;/P&gt;&lt;P&gt;Month1intersectMonth2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Month2intersectMonth3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Month3intersectMonth4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;Output 2:&lt;/P&gt;&lt;P&gt;Month2intersectMonth1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Month3intersectunion(2,1)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Month4intersectunion(3,2,1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Output 1 is the number of rows that have values from one month to the next.&lt;/P&gt;&lt;P&gt;Output 2 is the number of rows that have non-unique entries in the preceding columns.&lt;/P&gt;&lt;P&gt;Note: for this to work, an if then else statement may have to be applied to turn the data set into 1s and missing.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 May 2014 13:21:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147812#M39113</guid>
      <dc:creator>brettmullga</dc:creator>
      <dc:date>2014-05-15T13:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to Match Observations from one Variable to another Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147813#M39114</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Try:&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; attrib p format=$20. m1-m4 format=best.;&lt;BR /&gt;&amp;nbsp; infile datalines delimiter=',';&lt;BR /&gt;&amp;nbsp; input p $ m1-m4;&lt;BR /&gt;datalines;&lt;BR /&gt;1,8,1,., 9 &lt;BR /&gt;2,.,.,3,15 &lt;BR /&gt;3,4,5,.,12 &lt;BR /&gt;4,1,.,.,10 &lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;proc sql;&lt;BR /&gt;&amp;nbsp; create table OUTPUT1 &lt;BR /&gt;&amp;nbsp; (&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MONTH1INTERSECTMONTH2 num,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MONTH2INTERSECTMONTH3 num,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MONTH3INTERSECTMONTH4 num&lt;BR /&gt;&amp;nbsp; );&lt;BR /&gt;&amp;nbsp; create table OUTPUT2&lt;BR /&gt;&amp;nbsp; (&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MONTH2INTERSECTMONTH1 num,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MONTH3INTERSECTMONTH21 num,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MONTH4INTERSECTMONTH321 num&lt;BR /&gt;&amp;nbsp; );&lt;BR /&gt;&amp;nbsp; insert into OUTPUT1&lt;BR /&gt;&amp;nbsp; set MONTH1INTERSECTMONTH2=(select count(P) from WORK.HAVE where M1 is not null and M2 is not null),&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MONTH2INTERSECTMONTH3=(select count(P) from WORK.HAVE where M2 is not null and M3 is not null),&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MONTH3INTERSECTMONTH4=(select count(P) from WORK.HAVE where M3 is not null and M4 is not null);&lt;BR /&gt;&amp;nbsp; insert into OUTPUT2&lt;BR /&gt;&amp;nbsp; set MONTH2INTERSECTMONTH1=(select count(P) from WORK.HAVE where M2 is not null and M1 is not null),&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MONTH3INTERSECTMONTH21=(select count(P) from WORK.HAVE where M3 is not null and (M2 is not null or M1 is not null)),&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MONTH4INTERSECTMONTH321=(select count(P) from WORK.HAVE where M4 is not null and (M3 is not null or M2 is not null or M1 is not null));&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 May 2014 13:59:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147813#M39114</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-05-15T13:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to Match Observations from one Variable to another Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147814#M39115</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi brettmullga,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please find below the solution using datastep and sql. I have created a dataset based on the information you gave and tried to get the result in the final dataset. If you have more months column then the coding would need to be updated. Please let me know if you have any questions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All the best.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;Rafi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA original;&lt;/P&gt;&lt;P&gt;INPUT Participant Month1 Month2 Month3 Month4;&lt;/P&gt;&lt;P&gt;CARDS;&lt;/P&gt;&lt;P&gt;1 8 1 . 9&lt;/P&gt;&lt;P&gt;2 . . 3 15&lt;/P&gt;&lt;P&gt;3 4 5 . 12&lt;/P&gt;&lt;P&gt;4 1 . . 10&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;* Count total for each month;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp; CREATE TABLE m_tot AS&lt;/P&gt;&lt;P&gt;&amp;nbsp; SELECT *, COUNT (*) as total, COUNT(month1) AS m1_tot, COUNT(month2) AS m2_tot, COUNT(month3) AS m3_tot, COUNT(month4) AS m4_tot &lt;/P&gt;&lt;P&gt;&amp;nbsp; FROM original&lt;/P&gt;&lt;P&gt;&amp;nbsp; ORDER BY participant;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;* Using datasetp - 1) flag patient movement in each month and 2) flag patient who has value in previous month(s);&lt;/P&gt;&lt;P&gt;DATA flag;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SET m_tot;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF month1 NE . AND month2 NE . THEN m1tom2f = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF month2 NE . AND month3 NE . THEN m2tom3f = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF month3 NE . AND month4 NE . THEN m3tom4f = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; IF month2 NE . AND month1 NE . THEN m2tom1f = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF month3 NE . AND N(month1,month2)&amp;nbsp; GE 1 THEN m3tom1f = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF month4 NE . AND N(month1,month2,month3) GE 1 THEN m4tom1f = 1;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;* Using proc sql - count necessary values;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp; CREATE TABLE finalx AS&lt;/P&gt;&lt;P&gt;&amp;nbsp; SELECT *, COUNT(m1tom2f) AS m1tom2, COUNT(m2tom3f) AS m2tom3, COUNT(m3tom4f) AS m3tom4, COUNT(m2tom1f) AS m2tom1, COUNT(m3tom1f) AS m3tom1, COUNT(m4tom1f) AS m4tom1&lt;/P&gt;&lt;P&gt;&amp;nbsp; FROM flag&lt;/P&gt;&lt;P&gt;&amp;nbsp; ORDER BY participant;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;* Final dataset where all the necessary information for outputs will be found;&lt;/P&gt;&lt;P&gt;DATA final;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SET finalx (DROP=participant month1 month2 month3 month4&amp;nbsp; m1tom2f m2tom3f m3tom4f m2tom1f m3tom1f m4tom1f) END=eof ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF eof;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; LABEL total = 'Toatl participant'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m1_tot = 'Total participant in Month 1'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m2_tot = 'Total participant in Month 2'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m3_tot = 'Total participant in Month 3'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m4_tot = 'Total participant in Month 4'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m1tom2 = 'Participated in Month 1 and Month 2'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m2tom3 = 'Participated in Month 2 and Month 3'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m3tom4 = 'Participated in Month 3 and Month 4'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m2tom1 = 'Participated in Month 2 and in earlier month(s)'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m3tom1 = 'Participated in Month 3 and in earlier month(s)'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m4tom1 = 'Participated in Month 4 and in earlier month(s)'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 May 2014 15:34:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147814#M39115</guid>
      <dc:creator>RafiRahi</dc:creator>
      <dc:date>2014-05-15T15:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to Match Observations from one Variable to another Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147815#M39116</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or you could use this after the initial read in:&lt;/P&gt;&lt;P&gt;data have2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array mon (4) m1-m4;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array moni (3) mi1-mi3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i = 1 to 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if mon(i) ~=. and mon(i+1)~=. then moni(i) = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else moni(i) = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select distinct sum(mi1) as mi1, sum(mi2) as mi2, sum(mi3) as mi3, sum(case when m2~=. and m1 ~=. then 1 else 0 end) as m2mi1,&lt;/P&gt;&lt;P&gt;sum(case when m3~=. and (m1~=. or m2~=.) then 1 else 0 end) as m3mi12, sum(case when m4 ~=. and (m1~=. or m2 ~=. or m3 ~=.) then 1 else 0 end) as m4mi123&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from have2;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 May 2014 15:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Match-Observations-from-one-Variable-to-another-Variable/m-p/147815#M39116</guid>
      <dc:creator>overmar</dc:creator>
      <dc:date>2014-05-15T15:53:56Z</dc:date>
    </item>
  </channel>
</rss>

