<?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 Where and Keep statements together in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Where-and-Keep-statements-together/m-p/726258#M225679</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I am trying to write both Where and Keep statements.&lt;/P&gt;
&lt;P&gt;Firstly where should be done and then keep.&lt;/P&gt;
&lt;P&gt;I receive an error.&lt;/P&gt;
&lt;P&gt;What is the way to solve it?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: Variable date is not on file WORK.WANT_MONTH.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_date=31JAN2021;
%let end_date=14MAR2021;
data want_month(where=(date&amp;gt;"&amp;amp;start_date"d)keep=tbl_name);
date="&amp;amp;start_date"d;
do while (date&amp;lt;="&amp;amp;end_date"d);
    output;
    date=intnx('day', date, 1);
	date_ddmmyyyy=put(date,ddmmyyn8.);
	tbl_name=CATS("RRR.NewMethologyInput",date_ddmmyyyy);
end;
format date date9.;
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>Mon, 15 Mar 2021 13:01:30 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2021-03-15T13:01:30Z</dc:date>
    <item>
      <title>Where and Keep statements together</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-and-Keep-statements-together/m-p/726258#M225679</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I am trying to write both Where and Keep statements.&lt;/P&gt;
&lt;P&gt;Firstly where should be done and then keep.&lt;/P&gt;
&lt;P&gt;I receive an error.&lt;/P&gt;
&lt;P&gt;What is the way to solve it?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: Variable date is not on file WORK.WANT_MONTH.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_date=31JAN2021;
%let end_date=14MAR2021;
data want_month(where=(date&amp;gt;"&amp;amp;start_date"d)keep=tbl_name);
date="&amp;amp;start_date"d;
do while (date&amp;lt;="&amp;amp;end_date"d);
    output;
    date=intnx('day', date, 1);
	date_ddmmyyyy=put(date,ddmmyyn8.);
	tbl_name=CATS("RRR.NewMethologyInput",date_ddmmyyyy);
end;
format date date9.;
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>Mon, 15 Mar 2021 13:01:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-and-Keep-statements-together/m-p/726258#M225679</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-03-15T13:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: Where and Keep statements together</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-and-Keep-statements-together/m-p/726267#M225685</link>
      <description>&lt;P&gt;Here's a useful tip: The data set options (DROP, KEEP, RENAME, WHERE,...) are processed in alphabetical order. Therefore the KEEP statement is processed before the WHERE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The best way to solve this problem is to use the WHERE statement (or a subsetting IF statement) in the body of the program and use the KEEP option for the output data set:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_month(keep=tbl_name);
date="&amp;amp;start_date"d;
do while (date&amp;lt;="&amp;amp;end_date"d);
    output;
    date=intnx('day', date, 1);
	date_ddmmyyyy=put(date,ddmmyyn8.);
	tbl_name=CATS("RRR.NewMethologyInput",date_ddmmyyyy);
end;
format date date9.;
if (date&amp;gt;"&amp;amp;start_date"d);   /* could also use a WHERE clause here */
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Mar 2021 13:11:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-and-Keep-statements-together/m-p/726267#M225685</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2021-03-15T13:11:58Z</dc:date>
    </item>
  </channel>
</rss>

