<?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: Keep 2 Variables based on conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432708#M107196</link>
    <description>&lt;P&gt;Then your first step should be converting your dates stored as character into real SAS date values. Since we now need to work with a newly created variable, switch from a where condition to a subsetting if:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data saspms.datensatz_new;
set saspms.datensatz_pms_neu;
format n_date ddmmyy10.;
n_date = input(notificationdate,ddmmyy10.);
if '01jan2014'd &amp;lt;= n_date &amp;lt;= '31dec2016'd and Art_der_Anzeige = "Erstanzeige";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jan 2018 13:21:06 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-01-31T13:21:06Z</dc:date>
    <item>
      <title>Keep 2 Variables based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432700#M107190</link>
      <description>&lt;P&gt;Hey guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with 9 Variables and 300 Observations. Now I want to keep some Observations based on some conditions.&lt;/P&gt;&lt;P&gt;I have a variable Notificationdate and I only need Observations between the 01/01/2014 and the 31/12/2016 and Observations where Art_der_Anzeige = Erstanzeige. I tried so many options but neither would work. Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data saspms.datensatz_new;&lt;BR /&gt;set saspms.datensatz_pms_neu;&lt;BR /&gt;where notificationdate &amp;lt;= 01/01/2014 &amp;amp; &amp;gt;= 31/12/2016 ;&lt;/P&gt;&lt;P&gt;where Art_der_Anzeige= Erstanzeige;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data saspms.datensatz_new;&lt;BR /&gt;set saspms.datensatz_pms_neu;&lt;BR /&gt;keep if notificationdate &amp;lt;= 01/01/2014 &amp;amp; &amp;gt;= 31/12/2016 and keep if Art_der_Anzeige= Erstanzeige;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 12:46:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432700#M107190</guid>
      <dc:creator>marysmith</dc:creator>
      <dc:date>2018-01-31T12:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: Keep 2 Variables based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432702#M107191</link>
      <description>&lt;P&gt;Do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data saspms.datensatz_new;
set saspms.datensatz_pms_neu;
where '01jan2014'd &amp;lt;= notificationdate &amp;lt;= '31dec2016'd and Art_der_Anzeige = "Erstanzeige";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;character literals must be enclosed in quotes&lt;/LI&gt;
&lt;LI&gt;date literals are specified in the above manner; other date notations only work in an input function with a proper informat&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Wed, 31 Jan 2018 13:00:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432702#M107191</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-31T13:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: Keep 2 Variables based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432703#M107192</link>
      <description>&lt;P&gt;The KEEP statement is not used to limit the&amp;nbsp;number of observations, but the number of variables. But the WHERE statement does what you want. Only you should limit it to one statement, which combines the two conditions. And then you need to change your SAS date constants (I assume that your dates are SAS dates in the format DDMMYY10.):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data saspms.datensatz_new;
  set saspms.datensatz_pms_neu;
  where '01JAN2014'd &amp;lt;= notificationdate &amp;lt;= '31DEC2016'D 
    and Art_der_Anzeige= Erstanzeige;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 13:04:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432703#M107192</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-01-31T13:04:50Z</dc:date>
    </item>
    <item>
      <title>Re: Keep 2 Variables based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432705#M107193</link>
      <description>Thank you for your quick respond. But unfortunately I got an error message:&lt;BR /&gt;ERROR: WHERE clause operator requires compatible variables.&lt;BR /&gt;What does it mean?&lt;BR /&gt;&lt;BR /&gt;Thank you so much!&lt;BR /&gt;</description>
      <pubDate>Wed, 31 Jan 2018 13:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432705#M107193</guid>
      <dc:creator>marysmith</dc:creator>
      <dc:date>2018-01-31T13:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: Keep 2 Variables based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432706#M107194</link>
      <description>&lt;P&gt;Maxim 3: Know your data.&lt;/P&gt;
&lt;P&gt;Run a proc contents on your dataset to determine variable types and assigned formats.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 13:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432706#M107194</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-31T13:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: Keep 2 Variables based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432707#M107195</link>
      <description>Yeah I did that. Both a character Variables..&lt;BR /&gt;</description>
      <pubDate>Wed, 31 Jan 2018 13:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432707#M107195</guid>
      <dc:creator>marysmith</dc:creator>
      <dc:date>2018-01-31T13:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: Keep 2 Variables based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432708#M107196</link>
      <description>&lt;P&gt;Then your first step should be converting your dates stored as character into real SAS date values. Since we now need to work with a newly created variable, switch from a where condition to a subsetting if:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data saspms.datensatz_new;
set saspms.datensatz_pms_neu;
format n_date ddmmyy10.;
n_date = input(notificationdate,ddmmyy10.);
if '01jan2014'd &amp;lt;= n_date &amp;lt;= '31dec2016'd and Art_der_Anzeige = "Erstanzeige";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 13:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432708#M107196</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-31T13:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: Keep 2 Variables based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432710#M107198</link>
      <description>&lt;P&gt;data saspms.datensatz_new;&lt;BR /&gt;set saspms.datensatz_pms_neu;&lt;BR /&gt;where notificationdate between&amp;nbsp; "01/01/2014"d and&amp;nbsp;&amp;nbsp;"31/12/2016"d and Art_der_Anzeige="Erstanzeige";&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 13:25:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432710#M107198</guid>
      <dc:creator>srinath3111</dc:creator>
      <dc:date>2018-01-31T13:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: Keep 2 Variables based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432714#M107199</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;create table&amp;nbsp;saspms.datensatz_new as&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;select * from&amp;nbsp;saspms.datensatz_pms_neu where&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;notificationdate&amp;nbsp;between("01/01/2014"d and&amp;nbsp;&amp;nbsp;"31/12/2016"d) and&amp;nbsp;Art_der_Anzeige="Erstanzeige";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 13:30:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432714#M107199</guid>
      <dc:creator>srinath3111</dc:creator>
      <dc:date>2018-01-31T13:30:30Z</dc:date>
    </item>
    <item>
      <title>Re: Keep 2 Variables based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432734#M107211</link>
      <description>Thank you so much! That helped me a lot.&lt;BR /&gt;But what if there is even more conditions? Just realized that I need something else. My Variable Art_der_Anzeige has 4 values: Erstanzeige, Änderungsanzeige, Beendigung, Abschlussbericht, I need all the cases where I have "Erstanzeige" between 2014-2016 and Änderungsanzeige/Abschlussbericht/Beendigung after 2014.&lt;BR /&gt;I tried it like this but it didnt work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;data saspms.versuch;&lt;BR /&gt;set saspms.datensatz_pms_neu;&lt;BR /&gt;format n_date1 ddmmyy10.;&lt;BR /&gt;n_date1 = input(notificationdate,ddmmyy10.);&lt;BR /&gt;if "01jan2014"d &amp;lt;= n_date1 Art_der_Anzeige = "Erstanzeige" or if Art_der_Anzeige NE "Erstanzeige" and n_date &amp;gt;= "01jan2014"d ;&lt;BR /&gt;</description>
      <pubDate>Wed, 31 Jan 2018 14:05:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432734#M107211</guid>
      <dc:creator>marysmith</dc:creator>
      <dc:date>2018-01-31T14:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: Keep 2 Variables based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432738#M107214</link>
      <description>&lt;P&gt;The syntax for the subsetting if is this:&lt;/P&gt;
&lt;P&gt;if &lt;EM&gt;condition&lt;/EM&gt; ;&lt;/P&gt;
&lt;P&gt;A condition is a piece of boolean logic; boolean operators are &lt;EM&gt;not, and, or&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;So your second if is wrong syntax, it should be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if "01jan2014"d &amp;lt;= n_date1 &amp;lt;= '31dec2016'd and Art_der_Anzeige = "Erstanzeige" or Art_der_Anzeige ne "Erstanzeige" and n_date &amp;gt;= "01jan2014"d;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that, in boolean logic, &lt;EM&gt;not&lt;/EM&gt; is evaluated before &lt;EM&gt;and&lt;/EM&gt;, and &lt;EM&gt;and&lt;/EM&gt; before &lt;EM&gt;or&lt;/EM&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 14:20:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-2-Variables-based-on-conditions/m-p/432738#M107214</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-31T14:20:56Z</dc:date>
    </item>
  </channel>
</rss>

