<?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: creating variable based on some criteria/logic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/creating-variable-based-on-some-criteria-logic/m-p/750138#M235884</link>
    <description>I am sorry, I should describe the problem more clearly.  Sample period means the sample year which is 2000 to 2019 in my data. Therefore, if someone (co_per_rol) has confidence more than 1 and shows this behavior at least twice between 2000 and 2019 then I will assign 1 from the first time he shows this behavior. Thanks, I got my answer from FreelanceReinhard.</description>
    <pubDate>Thu, 24 Jun 2021 10:32:33 GMT</pubDate>
    <dc:creator>Ramin1</dc:creator>
    <dc:date>2021-06-24T10:32:33Z</dc:date>
    <item>
      <title>creating variable based on some criteria/logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-variable-based-on-some-criteria-logic/m-p/750105#M235862</link>
      <description>&lt;P&gt;Hi experts, I have the attached data. I want to create another variable based on some criteria. The new variable High will have 1 if id (Co_per_role) score more than 100 percent (&amp;gt;1) in the confidence column/variable and show this same behavior at least twice in the sample period; I will assign 1 to high from the first time such behavior shows up else it will be 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance;&lt;/P&gt;
&lt;P&gt;co_per_rol year confidence High&lt;/P&gt;
&lt;P&gt;1234 2000 .87 0&lt;/P&gt;
&lt;P&gt;1234 2001 .78 0&lt;/P&gt;
&lt;P&gt;1234 2002 .45 0&lt;/P&gt;
&lt;P&gt;1235 2000 .5 0&lt;/P&gt;
&lt;P&gt;1235 2001 1.45 1&lt;/P&gt;
&lt;P&gt;1235 2002 .64 1&lt;/P&gt;
&lt;P&gt;1235 2003 1.2 1&lt;/P&gt;
&lt;P&gt;1236 2000 .67 0&lt;/P&gt;
&lt;P&gt;1236 2001 1.23 0&lt;/P&gt;
&lt;P&gt;1236 2002 .54 0&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jun 2021 06:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-variable-based-on-some-criteria-logic/m-p/750105#M235862</guid>
      <dc:creator>Ramin1</dc:creator>
      <dc:date>2021-06-24T06:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: creating variable based on some criteria/logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-variable-based-on-some-criteria-logic/m-p/750107#M235863</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;show this same behavior at least twice in the sample period&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;The behaviour only happens once in your example: once per year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also please post your data as code so we can easily use it.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jun 2021 07:27:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-variable-based-on-some-criteria-logic/m-p/750107#M235863</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-06-24T07:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: creating variable based on some criteria/logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-variable-based-on-some-criteria-logic/m-p/750110#M235866</link>
      <description>&lt;P&gt;You should define exactly what "sample period" means if it has any bearing on the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect you are looking for something like this:&lt;/P&gt;
&lt;PRE&gt;data want; 
   set sample;
   by co_per_rol;
   retain high;
   if first.co_per_rol then high=0;
   high = max(high, confidence &amp;gt;0);
run;&lt;/PRE&gt;
&lt;P&gt;This assumes the data is actually sorted by co_per_rol and year.&lt;/P&gt;
&lt;P&gt;Retain keeps the value of a variable across data step boundaries.&lt;/P&gt;
&lt;P&gt;The BY statement creates automatic variables indicating whether the current record is the first or last of a by group that is 1 (true) or 0 (false) and can be used to reset a variable for the first record.&lt;/P&gt;
&lt;P&gt;Max function returns the largest value, so if High has been set to 1 it stays1. The comparison Confidence &amp;gt; 0 will return 1 when true or 0 when false.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jun 2021 07:27:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-variable-based-on-some-criteria-logic/m-p/750110#M235866</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-24T07:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: creating variable based on some criteria/logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-variable-based-on-some-criteria-logic/m-p/750112#M235867</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/352342"&gt;@Ramin1&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your dataset is grouped by CO_PER_ROL and sorted by YEAR within the CO_PER_ROL BY-groups, you can use a double DOW loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=_:);
do _n=1 by 1 until(last.co_per_rol);
  set sample;
  by co_per_rol notsorted;
  if confidence&amp;gt;1 then do;
    if _y=. then _y=year;
    _c=sum(_c,1);
  end;
end;
do _n=1 to _n;
  set sample;
  High=_c&amp;gt;1 &amp;amp; year&amp;gt;=_y;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Jun 2021 07:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-variable-based-on-some-criteria-logic/m-p/750112#M235867</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-06-24T07:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: creating variable based on some criteria/logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-variable-based-on-some-criteria-logic/m-p/750138#M235884</link>
      <description>I am sorry, I should describe the problem more clearly.  Sample period means the sample year which is 2000 to 2019 in my data. Therefore, if someone (co_per_rol) has confidence more than 1 and shows this behavior at least twice between 2000 and 2019 then I will assign 1 from the first time he shows this behavior. Thanks, I got my answer from FreelanceReinhard.</description>
      <pubDate>Thu, 24 Jun 2021 10:32:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-variable-based-on-some-criteria-logic/m-p/750138#M235884</guid>
      <dc:creator>Ramin1</dc:creator>
      <dc:date>2021-06-24T10:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: creating variable based on some criteria/logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-variable-based-on-some-criteria-logic/m-p/750359#M236014</link>
      <description>&lt;P&gt;Pick &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;'s reply as the answer then please.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 04:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-variable-based-on-some-criteria-logic/m-p/750359#M236014</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-06-26T04:49:11Z</dc:date>
    </item>
  </channel>
</rss>

