<?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 assign groups to vales in a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-groups-to-vales-in-a-variable/m-p/594220#M170673</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input cust_id $   month $;
cards;
1112       Mar
1113       apr
1113       feb
1114        feb
1115        mar
1115       apr
1115        feb
;

proc sql;
create table want as
select *,case when count(cust_id)=2 then 'A' 
when count(cust_id)=3 then 'B' else ' ' end as New_var
from have
group by cust_id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 04 Oct 2019 20:12:20 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-10-04T20:12:20Z</dc:date>
    <item>
      <title>How to assign groups to vales in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-groups-to-vales-in-a-variable/m-p/594211#M170669</link>
      <description>&lt;P&gt;If I have a SAS dataset with the following values. I want to create a new variable and assign value"A" if cust_id is there 2 times in the table and assign value "B" if cust_id is there 3 times. For ex. For cust_id=1113, I want new variable value to be A and for cust_id=1115, I want new variable value to be B.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cust_id&amp;nbsp; &amp;nbsp;month&lt;/P&gt;&lt;P&gt;1112&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Mar&lt;/P&gt;&lt;P&gt;1113&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;apr&lt;/P&gt;&lt;P&gt;1113&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;feb&lt;/P&gt;&lt;P&gt;1114&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; feb&lt;/P&gt;&lt;P&gt;1115&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mar&lt;/P&gt;&lt;P&gt;1115&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;apr&lt;/P&gt;&lt;P&gt;1115&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; feb&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 19:58:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-groups-to-vales-in-a-variable/m-p/594211#M170669</guid>
      <dc:creator>meetagupta</dc:creator>
      <dc:date>2019-10-04T19:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign groups to vales in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-groups-to-vales-in-a-variable/m-p/594214#M170670</link>
      <description>&lt;P&gt;What if it's there 1 or 4 times?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 20:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-groups-to-vales-in-a-variable/m-p/594214#M170670</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-04T20:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign groups to vales in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-groups-to-vales-in-a-variable/m-p/594219#M170672</link>
      <description>&lt;P&gt;they can be set to missing..&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 20:11:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-groups-to-vales-in-a-variable/m-p/594219#M170672</guid>
      <dc:creator>meetagupta</dc:creator>
      <dc:date>2019-10-04T20:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign groups to vales in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-groups-to-vales-in-a-variable/m-p/594220#M170673</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input cust_id $   month $;
cards;
1112       Mar
1113       apr
1113       feb
1114        feb
1115        mar
1115       apr
1115        feb
;

proc sql;
create table want as
select *,case when count(cust_id)=2 then 'A' 
when count(cust_id)=3 then 'B' else ' ' end as New_var
from have
group by cust_id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Oct 2019 20:12:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-groups-to-vales-in-a-variable/m-p/594220#M170673</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-04T20:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign groups to vales in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-groups-to-vales-in-a-variable/m-p/594221#M170674</link>
      <description>&lt;P&gt;Ok. Do something like this&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input cust_id month $;
datalines;
1112 Mar
1113 apr
1113 feb
1114 feb
1115 mar
1115 apr
1115 feb
;

data want;
   do _N_=1 by 1 until (last.cust_id);
      set have;
      by cust_id;
   end;
   do until (last.cust_id);
      set have;
      by cust_id;
      if      _N_=2 then newValue='A';
      else if _N_=3 then newValue='B';
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;cust_id month newValue 
1112    Mar     
1113    apr   A 
1113    feb   A 
1114    feb     
1115    mar   B 
1115    apr   B 
1115    feb   B &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 20:27:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-groups-to-vales-in-a-variable/m-p/594221#M170674</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-04T20:27:29Z</dc:date>
    </item>
  </channel>
</rss>

