<?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 Pulling people with multiple rows without collapsing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Pulling-people-with-multiple-rows-without-collapsing/m-p/251262#M47436</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that is at the level of person and values of a categorical variable (categ_1). There are several possible values of categ_1 but no person can have more than 2 values. Each row also has a value for categ_2 and a date variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; categ_1 &amp;nbsp; &amp;nbsp; categ_2 &amp;nbsp; &amp;nbsp; date&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;abc &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;jkl &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/2009&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;def &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;mno &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/2010&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;abc &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mno &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/2009&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm trying to do is&amp;nbsp;isolate those people with multiple values of categ_1, and find out what their values of categ_2 are for each value of categ_1, by date (so the one with the earlier date is their first categ_1 and the one with the later date is their second categ_1).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I did was this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=want;&lt;/P&gt;&lt;P&gt;by ID date;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;set want;&lt;/P&gt;&lt;P&gt;by ID date;&lt;/P&gt;&lt;P&gt;if first.ID then first_categ_1=1;&lt;/P&gt;&lt;P&gt;else second_categ_1=1;&lt;/P&gt;&lt;P&gt;if first_categ_1=1 and categ_2='jkl' then new_var='First categ 1=JKL';&lt;/P&gt;&lt;P&gt;if first_categ_1=1 and categ_2='mno' then new_var='First categ 1=MNO';&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if second_categ_1=1 and categ_2='mno' then new_var='Second categ 1=MNO';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if second_categ_1=1 and categ_2='mno' then new_var='Second categ 1=MNO';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works fine and gives me the information I want; the issue is that I want to exclude anyone who only has one value for categ_1 from my frequencies. I'm not sure how to keep both rows for people with two rows with different values of categ_1 and get rid of the rows for those who only have one row with one value of categ_1. I don't want to collapse because of new_var which tells me what happened to each person's first categ_1 and second categ_1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated.&lt;/P&gt;</description>
    <pubDate>Fri, 19 Feb 2016 19:51:33 GMT</pubDate>
    <dc:creator>Walternate</dc:creator>
    <dc:date>2016-02-19T19:51:33Z</dc:date>
    <item>
      <title>Pulling people with multiple rows without collapsing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-people-with-multiple-rows-without-collapsing/m-p/251262#M47436</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that is at the level of person and values of a categorical variable (categ_1). There are several possible values of categ_1 but no person can have more than 2 values. Each row also has a value for categ_2 and a date variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; categ_1 &amp;nbsp; &amp;nbsp; categ_2 &amp;nbsp; &amp;nbsp; date&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;abc &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;jkl &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/2009&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;def &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;mno &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/2010&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;abc &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mno &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/2009&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm trying to do is&amp;nbsp;isolate those people with multiple values of categ_1, and find out what their values of categ_2 are for each value of categ_1, by date (so the one with the earlier date is their first categ_1 and the one with the later date is their second categ_1).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I did was this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=want;&lt;/P&gt;&lt;P&gt;by ID date;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;set want;&lt;/P&gt;&lt;P&gt;by ID date;&lt;/P&gt;&lt;P&gt;if first.ID then first_categ_1=1;&lt;/P&gt;&lt;P&gt;else second_categ_1=1;&lt;/P&gt;&lt;P&gt;if first_categ_1=1 and categ_2='jkl' then new_var='First categ 1=JKL';&lt;/P&gt;&lt;P&gt;if first_categ_1=1 and categ_2='mno' then new_var='First categ 1=MNO';&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if second_categ_1=1 and categ_2='mno' then new_var='Second categ 1=MNO';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if second_categ_1=1 and categ_2='mno' then new_var='Second categ 1=MNO';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works fine and gives me the information I want; the issue is that I want to exclude anyone who only has one value for categ_1 from my frequencies. I'm not sure how to keep both rows for people with two rows with different values of categ_1 and get rid of the rows for those who only have one row with one value of categ_1. I don't want to collapse because of new_var which tells me what happened to each person's first categ_1 and second categ_1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2016 19:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-people-with-multiple-rows-without-collapsing/m-p/251262#M47436</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2016-02-19T19:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling people with multiple rows without collapsing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-people-with-multiple-rows-without-collapsing/m-p/251303#M47458</link>
      <description>&lt;P&gt;It isn't clear, at least to me, if you want to exclude from an analysis but leave them in the data OR to remove the records from the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might be able to set a flag that allows either with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Categ_1_flag= ( first.id and last.id);&lt;/P&gt;
&lt;P&gt;If there is only one value for the ID variable then this flag will be 1 other wise 0.&lt;/P&gt;
&lt;P&gt;You could either drop the record with&lt;/P&gt;
&lt;P&gt;If categ_1_flag=0;&lt;/P&gt;
&lt;P&gt;or exclude from an analysis with a where statement or clause:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; where categ_1_flag=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables ....&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2016 22:29:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-people-with-multiple-rows-without-collapsing/m-p/251303#M47458</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-02-19T22:29:38Z</dc:date>
    </item>
  </channel>
</rss>

