<?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: Create a new  variable to flag combinations of two other variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-to-flag-combinations-of-two-other/m-p/861310#M340241</link>
    <description>Many thanks, works very well.</description>
    <pubDate>Tue, 28 Feb 2023 09:26:32 GMT</pubDate>
    <dc:creator>costasRO</dc:creator>
    <dc:date>2023-02-28T09:26:32Z</dc:date>
    <item>
      <title>Create a new  variable to flag combinations of two other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-to-flag-combinations-of-two-other/m-p/860622#M339972</link>
      <description>&lt;P&gt;Hello All&lt;/P&gt;
&lt;P&gt;I have a dataset that looks like this&lt;/P&gt;
&lt;P&gt;Fund&amp;nbsp; &amp;nbsp; Company&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/1990&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/1990&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/1990&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/1990&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/1990&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; D&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/1990&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a variable to indicate combinations of company and date like below:&lt;/P&gt;
&lt;P&gt;Fund&amp;nbsp; &amp;nbsp; Company&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Indicator&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/1990&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/1990&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/1990&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/1990&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/1990&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; D&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/1990&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have many funds, companies and dates in the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;many thanks for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Costas&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2023 10:05:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-to-flag-combinations-of-two-other/m-p/860622#M339972</guid>
      <dc:creator>costasRO</dc:creator>
      <dc:date>2023-02-24T10:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new  variable to flag combinations of two other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-to-flag-combinations-of-two-other/m-p/860639#M339979</link>
      <description>&lt;P&gt;You do not actually describe any RULE for creating the flag. As far as I can tell all you are doing is applying a number based solely on the value of Company and I have no idea what the result might be if you have any company with two or more dates or a company other than A, B, C or D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Programs require stated rules. Examples are helpful to demonstrate the rule, especially when more complex, but without a rule an example can be next to useless, especially when none of your company or dates differ within a group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Part of your Rule(s) that should be stated is apparently what ever that indicator is should reset for each fund.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2023 11:44:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-to-flag-combinations-of-two-other/m-p/860639#M339979</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-24T11:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new  variable to flag combinations of two other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-to-flag-combinations-of-two-other/m-p/860648#M339983</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Fund    Company   $           date   :mmddyy10.;
format date mmddyys10.;
cards;
   1           A                     1/1/1990          
   1           B                    1/1/1990          
   1           C                    1/1/1990         
  2            A                     1/1/1990         
  2            B                    1/1/1990          
 2            D                     1/1/1990     
;
data want;
 if _n_=1 then do;
   Indicator=0;
   if 0 then set have;
   declare hash h();
   h.definekey('Company','date');
   h.definedata('Indicator');
   h.definedone();
 end;
set have;
if h.find() ne 0 then do;n+1;Indicator=n;h.add();end;
drop n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Feb 2023 12:36:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-to-flag-combinations-of-two-other/m-p/860648#M339983</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-02-24T12:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new  variable to flag combinations of two other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-to-flag-combinations-of-two-other/m-p/860665#M339985</link>
      <description>&lt;P&gt;Not quite sure about the logic you want, But if you want Indicator to identify a unique Company-Date within Fund, then I think below might be what you want.&amp;nbsp; It uses the sum statement to create an accumulator variable that is set to 0 for each fund, and then increments each time a new value for Company or Date is encountered.&amp;nbsp; The BY-group processing requires the data to be sorted. I added more test data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Fund Company $ date :mmddyy10.;
format date mmddyys10.;
cards;
1 A 1/1/1990
1 A 1/1/1990
1 A 2/1/1990
1 B 1/1/1990
1 C 1/1/1990
2 A 1/1/1990
2 B 1/1/1990
2 D 1/1/1990
;

data want ;
  set have ;
  by fund company date ;
  if first.fund then Indicator=0 ;
  if first.date then Indicator++1 ;

  put Fund Company Date Indicator ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Returns:&lt;/P&gt;
&lt;PRE&gt;46   data want ;
47     set have ;
48     by fund company date ;
49     if first.fund then Indicator=0 ;
50     if first.date then Indicator++1 ;
51
52     put Fund Company Date Indicator ;
53   run ;

1 A 01/01/1990 1
1 A 01/01/1990 1
1 A 02/01/1990 2
1 B 01/01/1990 3
1 C 01/01/1990 4
2 A 01/01/1990 1
2 B 01/01/1990 2
2 D 01/01/1990 3
NOTE: There were 8 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 8 observations and 4 variables.
&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Feb 2023 13:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-to-flag-combinations-of-two-other/m-p/860665#M339985</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-02-24T13:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new  variable to flag combinations of two other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-to-flag-combinations-of-two-other/m-p/861310#M340241</link>
      <description>Many thanks, works very well.</description>
      <pubDate>Tue, 28 Feb 2023 09:26:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-to-flag-combinations-of-two-other/m-p/861310#M340241</guid>
      <dc:creator>costasRO</dc:creator>
      <dc:date>2023-02-28T09:26:32Z</dc:date>
    </item>
  </channel>
</rss>

