<?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: Proc Sql (or data step): assign records into groups based on multiple conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-or-data-step-assign-records-into-groups-based-on/m-p/649703#M194823</link>
    <description>Hi Ballardw - thanks for your note - the '.' values in this example set are assigned to all prov=SPEC type as they represent referrals or other providers that aren't assigned. In the dataset all of the providers (by type) are listed in the same column. It is only the provtype=MD that triggers a flag of 1 = this was the assigned provider or 0 = this was not their assigned provider. Either way, I need to keep all of the records in the dataset, so the missing values need to stay, though i admit i could just run a proc sql create table based on the grouper and then prob join back based on b.id = a.id and b.provtype = a.provtype.</description>
    <pubDate>Thu, 21 May 2020 20:51:58 GMT</pubDate>
    <dc:creator>N8</dc:creator>
    <dc:date>2020-05-21T20:51:58Z</dc:date>
    <item>
      <title>Proc Sql (or data step): assign records into groups based on multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-or-data-step-assign-records-into-groups-based-on/m-p/649685#M194815</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having difficult building a solution to a problem I'm working on where I assign a value to a recipient based on multiple conditions. This can be done in a data step or SQL.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Scenario: I'm working with a dataset that Has an ID variable, a claimtype (e.g., emergency, outpatient), the type of provider the person saw - and the important variable - was the provider they saw the one that was assigned to them.&amp;nbsp;In all instances, the recipients is going to have an ED encounter, and I need to keep this variable. What i want to do is group recipients into three groups (A) always saw assigned provider, (B) sometimes saw assigned provider, and (C) never saw assigned provider. Ultimately these new variables will be my grouping variables to run some frequency statistics on (with dependent variable being ED visit) .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've created a Want and Have dataset below. Any help on this is appreciated. I'm not too worried about the blanks that I have in the Want table as I plan to just populate the empty spaces using a Retain function, but if you know of an easier way to flag a recipient, by ID, into one of the 3 groups then that's also great!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you for your help, Nate&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Have;&lt;BR /&gt;input ID $ Claim $ provtype $ assigned &amp;amp;;&lt;BR /&gt;datalines ;&lt;BR /&gt;1 ED EM .&lt;BR /&gt;1 OP SPEC .&lt;BR /&gt;1 OP SPEC .&lt;BR /&gt;1 OP MD 1&lt;BR /&gt;1 OP MD 0&lt;BR /&gt;2 ED EM .&lt;BR /&gt;2 OP MD 1&lt;BR /&gt;2 OP MD 1&lt;BR /&gt;3 ED EM .&lt;BR /&gt;3 OP SPEC .&lt;BR /&gt;3 OP MD 1&lt;BR /&gt;3 OP MD 1&lt;BR /&gt;3 OP MD 1&lt;BR /&gt;3 OP MD 1&lt;BR /&gt;3 OP MD 1&lt;BR /&gt;4 ED EM .&lt;BR /&gt;4 OP MD 0&lt;BR /&gt;4 OP SPEC .&lt;BR /&gt;4 OP MD 0&lt;BR /&gt;;&lt;BR /&gt;;&lt;BR /&gt;run ;&lt;BR /&gt;data want;&lt;BR /&gt;input ID $ Claim $ provtype $ assigned &amp;amp; both $ always $ never $;&lt;BR /&gt;datalines ;&lt;BR /&gt;1 ED EM . . . .&lt;BR /&gt;1 OP SPEC . . . .&lt;BR /&gt;1 OP SPEC . . . .&lt;BR /&gt;1 OP MD 1 1 . .&lt;BR /&gt;1 OP MD 0 1 . .&lt;BR /&gt;2 ED EM . . . .&lt;BR /&gt;2 OP MD 1 . 1 .&lt;BR /&gt;2 OP MD 1 . 1 .&lt;BR /&gt;3 ED EM . . . .&lt;BR /&gt;3 OP SPEC . . . .&lt;BR /&gt;3 OP MD 1 1 . .&lt;BR /&gt;3 OP MD 1 1 . .&lt;BR /&gt;3 OP MD 1 1 . .&lt;BR /&gt;3 OP MD 1 1 . .&lt;BR /&gt;3 OP MD 1 1 . .&lt;BR /&gt;4 ED EM . . . .&lt;BR /&gt;4 OP MD 0 . . 1&lt;BR /&gt;4 OP SPEC . . . .&lt;BR /&gt;4 OP MD 0 . . 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2020 19:32:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-or-data-step-assign-records-into-groups-based-on/m-p/649685#M194815</guid>
      <dc:creator>N8</dc:creator>
      <dc:date>2020-05-21T19:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql (or data step): assign records into groups based on multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-or-data-step-assign-records-into-groups-based-on/m-p/649686#M194816</link>
      <description>Is seeing the assigned provider true when assigned=provtype? Or how is that defined?</description>
      <pubDate>Thu, 21 May 2020 19:38:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-or-data-step-assign-records-into-groups-based-on/m-p/649686#M194816</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-05-21T19:38:31Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql (or data step): assign records into groups based on multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-or-data-step-assign-records-into-groups-based-on/m-p/649700#M194821</link>
      <description>&lt;P&gt;You show for your have data:&lt;/P&gt;
&lt;PRE&gt;input ID $ Claim $ provtype $ assigned &amp;amp;;
datalines ;
1 ED EM .
1 OP SPEC .
1 OP SPEC .
1 OP MD 1
1 OP MD 0
2 ED EM .&lt;/PRE&gt;
&lt;P&gt;which shows a large number of Assigned values as missing. Why? I would think, from you problem description it should be there everytime.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I really wouldn't add three variables one could do it just fine (with a format).&lt;/P&gt;
&lt;P&gt;If you average the assigned variable per Id you get the percentage of times assigned is 1. So a value of 0 would mean "never", 1 "always" and anything else "sometimes". Which groups could be defined with a format&lt;/P&gt;
&lt;PRE&gt;Proc format;
value assigned
0 = 'Never'
0 &amp;lt;-&amp;lt;1 = 'Sometimes'
1 ='Always'
;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 May 2020 20:25:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-or-data-step-assign-records-into-groups-based-on/m-p/649700#M194821</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-21T20:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql (or data step): assign records into groups based on multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-or-data-step-assign-records-into-groups-based-on/m-p/649701#M194822</link>
      <description>Hi Reeza - Sorry about that - prototype 1 = went to assigned provider, prototype = 0 did not go to assigned provider. The values could also be character. They are flagged as 1/0 in the database. In this example, prototype = SPEC is unimportant. It's prototype = MD that is important as this is the provider type that is triggering the flag.</description>
      <pubDate>Thu, 21 May 2020 20:48:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-or-data-step-assign-records-into-groups-based-on/m-p/649701#M194822</guid>
      <dc:creator>N8</dc:creator>
      <dc:date>2020-05-21T20:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql (or data step): assign records into groups based on multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-or-data-step-assign-records-into-groups-based-on/m-p/649703#M194823</link>
      <description>Hi Ballardw - thanks for your note - the '.' values in this example set are assigned to all prov=SPEC type as they represent referrals or other providers that aren't assigned. In the dataset all of the providers (by type) are listed in the same column. It is only the provtype=MD that triggers a flag of 1 = this was the assigned provider or 0 = this was not their assigned provider. Either way, I need to keep all of the records in the dataset, so the missing values need to stay, though i admit i could just run a proc sql create table based on the grouper and then prob join back based on b.id = a.id and b.provtype = a.provtype.</description>
      <pubDate>Thu, 21 May 2020 20:51:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-or-data-step-assign-records-into-groups-based-on/m-p/649703#M194823</guid>
      <dc:creator>N8</dc:creator>
      <dc:date>2020-05-21T20:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql (or data step): assign records into groups based on multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-or-data-step-assign-records-into-groups-based-on/m-p/649705#M194824</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select *, 
case when max(assigned)=min(assigned) = 1 then 'Always see assigned provider'
when max(assigned) = min(assigned) = 0 then 'Never saw assigned provider'
when max(assigned) ne min(assigned) then 'Sometimes see assigned provider' 
else 'CHECKME' end as group_status
group by ID;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/105992"&gt;@N8&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi Reeza - Sorry about that - prototype 1 = went to assigned provider, prototype = 0 did not go to assigned provider. The values could also be character. They are flagged as 1/0 in the database. In this example, prototype = SPEC is unimportant. It's prototype = MD that is important as this is the provider type that is triggering the flag.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2020 20:55:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-or-data-step-assign-records-into-groups-based-on/m-p/649705#M194824</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-05-21T20:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql (or data step): assign records into groups based on multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-or-data-step-assign-records-into-groups-based-on/m-p/649725#M194829</link>
      <description>&lt;P&gt;Yes, attach the value back to the records that need it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't generally add summary type values back to every record of a data set as there are just too many ways for such to get misunderstood or forget what they are there for if the set isn't used for awhile, or I have a "senior moment" reusing the data for another purpose.&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2020 22:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-or-data-step-assign-records-into-groups-based-on/m-p/649725#M194829</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-21T22:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql (or data step): assign records into groups based on multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-or-data-step-assign-records-into-groups-based-on/m-p/649726#M194830</link>
      <description>perfect - i can work with this to get exactly what I am trying to figure out. Thank you!</description>
      <pubDate>Thu, 21 May 2020 22:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-or-data-step-assign-records-into-groups-based-on/m-p/649726#M194830</guid>
      <dc:creator>N8</dc:creator>
      <dc:date>2020-05-21T22:14:11Z</dc:date>
    </item>
  </channel>
</rss>

