<?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 Updating WHERE clause in a data step and losing records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Updating-WHERE-clause-in-a-data-step-and-losing-records/m-p/649485#M194729</link>
    <description>&lt;P&gt;I am trying to automate a claims pull process where I assign a time period based on macro date variables. When I run&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;want_R12_prev&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;and&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;want_R12_curr&lt;/STRONG&gt;&lt;/EM&gt; as data steps by themselves, I get the desired number of records for each time period.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_R12_prev;
set claims_data;
By var1 var2 var3;
where datepart(Dt_Activity) &amp;lt;= &amp;amp;PrevRunOut.;
if datepart(Dt_Incurred) &amp;gt;= &amp;amp;FromDtPrev. 
     And datepart(Dt_Incurred) &amp;lt;= &amp;amp;ToDtPrev.
     And datepart(Dt_Activity) &amp;lt;= &amp;amp;PrevRunOut. 
     And last.ClmLn Then Rolling12 = "Rolling 12 - 1YrP";
run;

data want_R12_curr;
set claims_data;
By var1 var2 var3;
where datepart(Dt_Activity) &amp;lt;= &amp;amp;CurrentRunOut.;
if datepart(Dt_Incurred) &amp;gt;= &amp;amp;FromDtCurrent. 
     And datepart(Dt_Incurred) &amp;lt;= &amp;amp;ToDtCurrent.
     And datepart(Dt_Activity) &amp;lt;= &amp;amp;CurrentRunOut. 
     And last.ClmLn Then Rolling12 = "Rolling 12 - CYrP";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But when I try to run them together in one data step,&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;want_multiple&lt;/STRONG&gt;&lt;/EM&gt;,&amp;nbsp;it does not bring back all the records the individual data steps bring back. I am attempting to assign a YTD period, then invoke the Where clause twice to assign two different Rolling12 periods. The Where does not appear to do anything as I get the same number of records back as I do without it in the code. The actual code has many more period assignments so instead of creating and joining 30+ different data steps I was wondering if my goal of assigning multiple types of time periods is possible to do in one step?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_multiple;
set claims_data;
By var1 var2 var3;

if datepart(Dt_Incurred) &amp;gt;= &amp;amp;FromDt2019. 
	And datepart(Dt_Incurred) &amp;lt;= &amp;amp;ToDt2019.
	And datepart(Dt_Activity) &amp;lt;= &amp;amp;ToDt2019.
	And last.Clmln Then Year = "Year to Date - 1YrP";
else if datepart(Dt_Incurred) &amp;gt;= &amp;amp;FromDt2020. 
	And datepart(Dt_Incurred) &amp;lt;= &amp;amp;ToDt2020. 
	And datepart(Dt_Activity) &amp;lt;= &amp;amp;ToDt2020.
	And last.Clmln Then Year = "Year to Date - CYr";

where datepart(Dt_Activity) &amp;lt;= &amp;amp;PrevRunOut.;
if datepart(Dt_Incurred) &amp;gt;= &amp;amp;FromDtPrev. 
     And datepart(Dt_Incurred) &amp;lt;= &amp;amp;ToDtPrev.
     And datepart(Dt_Activity) &amp;lt;= &amp;amp;PrevRunOut. 
     And last.ClmLn Then Rolling12 = "Rolling 12 - 1YrP";

where datepart(Dt_Activity) &amp;lt;= &amp;amp;CurrentRunOut.;
if datepart(Dt_Incurred) &amp;gt;= &amp;amp;FromDtCurrent. 
     And datepart(Dt_Incurred) &amp;lt;= &amp;amp;ToDtCurrent.
     And datepart(Dt_Activity) &amp;lt;= &amp;amp;CurrentRunOut. 
     And last.ClmLn Then Rolling12 = "Rolling 12 - CYrP";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Big thanks and any input is greatly appreciated!&lt;/P&gt;</description>
    <pubDate>Thu, 21 May 2020 07:46:18 GMT</pubDate>
    <dc:creator>zmalone91</dc:creator>
    <dc:date>2020-05-21T07:46:18Z</dc:date>
    <item>
      <title>Updating WHERE clause in a data step and losing records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-WHERE-clause-in-a-data-step-and-losing-records/m-p/649485#M194729</link>
      <description>&lt;P&gt;I am trying to automate a claims pull process where I assign a time period based on macro date variables. When I run&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;want_R12_prev&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;and&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;want_R12_curr&lt;/STRONG&gt;&lt;/EM&gt; as data steps by themselves, I get the desired number of records for each time period.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_R12_prev;
set claims_data;
By var1 var2 var3;
where datepart(Dt_Activity) &amp;lt;= &amp;amp;PrevRunOut.;
if datepart(Dt_Incurred) &amp;gt;= &amp;amp;FromDtPrev. 
     And datepart(Dt_Incurred) &amp;lt;= &amp;amp;ToDtPrev.
     And datepart(Dt_Activity) &amp;lt;= &amp;amp;PrevRunOut. 
     And last.ClmLn Then Rolling12 = "Rolling 12 - 1YrP";
run;

data want_R12_curr;
set claims_data;
By var1 var2 var3;
where datepart(Dt_Activity) &amp;lt;= &amp;amp;CurrentRunOut.;
if datepart(Dt_Incurred) &amp;gt;= &amp;amp;FromDtCurrent. 
     And datepart(Dt_Incurred) &amp;lt;= &amp;amp;ToDtCurrent.
     And datepart(Dt_Activity) &amp;lt;= &amp;amp;CurrentRunOut. 
     And last.ClmLn Then Rolling12 = "Rolling 12 - CYrP";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But when I try to run them together in one data step,&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;want_multiple&lt;/STRONG&gt;&lt;/EM&gt;,&amp;nbsp;it does not bring back all the records the individual data steps bring back. I am attempting to assign a YTD period, then invoke the Where clause twice to assign two different Rolling12 periods. The Where does not appear to do anything as I get the same number of records back as I do without it in the code. The actual code has many more period assignments so instead of creating and joining 30+ different data steps I was wondering if my goal of assigning multiple types of time periods is possible to do in one step?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_multiple;
set claims_data;
By var1 var2 var3;

if datepart(Dt_Incurred) &amp;gt;= &amp;amp;FromDt2019. 
	And datepart(Dt_Incurred) &amp;lt;= &amp;amp;ToDt2019.
	And datepart(Dt_Activity) &amp;lt;= &amp;amp;ToDt2019.
	And last.Clmln Then Year = "Year to Date - 1YrP";
else if datepart(Dt_Incurred) &amp;gt;= &amp;amp;FromDt2020. 
	And datepart(Dt_Incurred) &amp;lt;= &amp;amp;ToDt2020. 
	And datepart(Dt_Activity) &amp;lt;= &amp;amp;ToDt2020.
	And last.Clmln Then Year = "Year to Date - CYr";

where datepart(Dt_Activity) &amp;lt;= &amp;amp;PrevRunOut.;
if datepart(Dt_Incurred) &amp;gt;= &amp;amp;FromDtPrev. 
     And datepart(Dt_Incurred) &amp;lt;= &amp;amp;ToDtPrev.
     And datepart(Dt_Activity) &amp;lt;= &amp;amp;PrevRunOut. 
     And last.ClmLn Then Rolling12 = "Rolling 12 - 1YrP";

where datepart(Dt_Activity) &amp;lt;= &amp;amp;CurrentRunOut.;
if datepart(Dt_Incurred) &amp;gt;= &amp;amp;FromDtCurrent. 
     And datepart(Dt_Incurred) &amp;lt;= &amp;amp;ToDtCurrent.
     And datepart(Dt_Activity) &amp;lt;= &amp;amp;CurrentRunOut. 
     And last.ClmLn Then Rolling12 = "Rolling 12 - CYrP";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Big thanks and any input is greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2020 07:46:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-WHERE-clause-in-a-data-step-and-losing-records/m-p/649485#M194729</guid>
      <dc:creator>zmalone91</dc:creator>
      <dc:date>2020-05-21T07:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: Updating WHERE clause in a data step and losing records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-WHERE-clause-in-a-data-step-and-losing-records/m-p/649499#M194734</link>
      <description>When the DATA step uses multiple WHERE statements, each one replaces any earlier WHERE statement.  Only the last one has any impact.&lt;BR /&gt;&lt;BR /&gt;Since your IF THEN conditions repeat the WHERE conditions, just remove all WHERE statements.  Then add at the end of the data step:&lt;BR /&gt;&lt;BR /&gt;if rolling12 ne " " ;</description>
      <pubDate>Thu, 21 May 2020 08:54:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-WHERE-clause-in-a-data-step-and-losing-records/m-p/649499#M194734</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-05-21T08:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: Updating WHERE clause in a data step and losing records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-WHERE-clause-in-a-data-step-and-losing-records/m-p/649537#M194742</link>
      <description>&lt;P&gt;The WHERE clause limits the records passed from the source dataset into the data step.&amp;nbsp; The main effect it might have on the logic of your example code is its impact on the LAST. variable you are referencing.&amp;nbsp; If a group has 10 records in your source but the last 2 do not pass the where clause test then the 8th record is the LAST instead of the 10th record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You cannot apply two independent where clauses in the same data step without reading the source dataset twice.&amp;nbsp; You can augment the WHERE clause by using a WHERE ALSO statement, but that is just the same as writing one WHERE statement with both conditions combine with AND operator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might be able to do some more complex calculations in a single data step, but you would need to explain more clearly what you are tying to do.&amp;nbsp; For example if you want to aggregate over a patient (find the min vlaue or max value or count something) but use different criteria for which records to include in each aggregate you could.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2020 11:55:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-WHERE-clause-in-a-data-step-and-losing-records/m-p/649537#M194742</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-05-21T11:55:16Z</dc:date>
    </item>
  </channel>
</rss>

