<?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: How to filter date variable for a series of datasets? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-date-variable-for-a-series-of-datasets/m-p/739547#M230840</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Remove the formats from the macro variables so that SAS will understand the values to be dates&lt;/LI&gt;
&lt;LI&gt;Apply the formats where needed using %SYFUNC() and PUTN()&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  (where("&amp;amp;Start_d11"d&amp;lt;=date&amp;lt;="&amp;amp;SCORING_DATE"d)) &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Resolves to the following which is not valid SAS syntax. So assuming your dates are SAS dates, leave it as an unformatted date by removing the PUT() and displayed format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  (where("20200506"d&amp;lt;=date&amp;lt;="20210506"d)) &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This should work instead, untested as no data etc..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;

call symputx('Start_d11', intnx('month', today(),0));

call symputx('SCORING_DATE' , intnx('day', today(), -1, 's'));

run;

 

data ABCD&amp;amp;Start_d1. - ABCD%sysfunc(putn(&amp;amp;SCORING_DATE1. , yymmddn8.)       (where(&amp;amp;Start_d11&amp;lt;=date&amp;lt;=SCORING_DATE)) ;
set ABC&amp;amp;Start_d1. - ABC%sysfunc(&amp;amp;SCORING_DATE1., yymmddn8.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361528"&gt;@Shradha1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;I have datasets with their names indexed on date, say ABC_20210424,&amp;nbsp;ABC_20210425,&amp;nbsp;ABC_20210426 and so on.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Each dataset contains the same variables and one variable is Date. I have to use these datasets for a range of days, suppose from 15 APR 2021 to 30APR 2021 and within each dataset I want to select only those observations for which the Date variable takes value equal to the date indexed on the dataset name. For example,&amp;nbsp;ABC_20210424 dataset has a range of observations with varying dates, but I want to select only those observations where Date=20210424. How do I achieve this? I am trying the following piece of code but its giving the error:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;lt;LINE and COLUMN cannot be determined&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Code I am using:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;call symputx('Start_d11', put(intnx('month', today(),0), yymmddn8.));&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;call symputx('SCORING_DATE' , put(intnx('day', today(), -1, 's'), yymmddn8.));&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data ABCD&amp;amp;Start_d1. - ABCD&amp;amp;SCORING_DATE1.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (where("&amp;amp;Start_d11"d&amp;lt;=date&amp;lt;="&amp;amp;SCORING_DATE"d)) ;&lt;BR /&gt;set ABC&amp;amp;Start_d1. - ABC&amp;amp;SCORING_DATE1.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 06 May 2021 16:12:11 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-05-06T16:12:11Z</dc:date>
    <item>
      <title>How to filter date variable for a series of datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-date-variable-for-a-series-of-datasets/m-p/739499#M230814</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I have datasets with their names indexed on date, say ABC_20210424,&amp;nbsp;ABC_20210425,&amp;nbsp;ABC_20210426 and so on.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Each dataset contains the same variables and one variable is Date. I have to use these datasets for a range of days, suppose from 15 APR 2021 to 30APR 2021 and within each dataset I want to select only those observations for which the Date variable takes value equal to the date indexed on the dataset name. For example,&amp;nbsp;ABC_20210424 dataset has a range of observations with varying dates, but I want to select only those observations where Date=20210424. How do I achieve this? I am trying the following piece of code but its giving the error:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;lt;LINE and COLUMN cannot be determined&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Code I am using:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;call symputx('Start_d11', put(intnx('month', today(),0), yymmddn8.));&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;call symputx('SCORING_DATE' , put(intnx('day', today(), -1, 's'), yymmddn8.));&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data ABCD&amp;amp;Start_d1. - ABCD&amp;amp;SCORING_DATE1.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (where("&amp;amp;Start_d11"d&amp;lt;=date&amp;lt;="&amp;amp;SCORING_DATE"d)) ;&lt;BR /&gt;set ABC&amp;amp;Start_d1. - ABC&amp;amp;SCORING_DATE1.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help!&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 14:39:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-date-variable-for-a-series-of-datasets/m-p/739499#M230814</guid>
      <dc:creator>Shradha1</dc:creator>
      <dc:date>2021-05-06T14:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter date variable for a series of datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-date-variable-for-a-series-of-datasets/m-p/739503#M230818</link>
      <description>&lt;P&gt;Use the INDSNAME= option of the SET statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ABC_20210424;
input id $ date :yymmdd8.;
format date yymmdd10.;
datalines;
A 20210424
A 20210425
;

data ABC_20210425;
input id $ date :yymmdd8.;
format date yymmdd10.;
datalines;
B 20210424
B 20210425
;

data want;
length inds $41;
set
  ABC_20210424
  ABC_20210425
  indsname=inds
;
if date = input(scan(scan(inds,2,"."),2,"_"),yymmdd8.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 May 2021 14:55:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-date-variable-for-a-series-of-datasets/m-p/739503#M230818</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-06T14:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter date variable for a series of datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-date-variable-for-a-series-of-datasets/m-p/739547#M230840</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Remove the formats from the macro variables so that SAS will understand the values to be dates&lt;/LI&gt;
&lt;LI&gt;Apply the formats where needed using %SYFUNC() and PUTN()&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  (where("&amp;amp;Start_d11"d&amp;lt;=date&amp;lt;="&amp;amp;SCORING_DATE"d)) &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Resolves to the following which is not valid SAS syntax. So assuming your dates are SAS dates, leave it as an unformatted date by removing the PUT() and displayed format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  (where("20200506"d&amp;lt;=date&amp;lt;="20210506"d)) &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This should work instead, untested as no data etc..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;

call symputx('Start_d11', intnx('month', today(),0));

call symputx('SCORING_DATE' , intnx('day', today(), -1, 's'));

run;

 

data ABCD&amp;amp;Start_d1. - ABCD%sysfunc(putn(&amp;amp;SCORING_DATE1. , yymmddn8.)       (where(&amp;amp;Start_d11&amp;lt;=date&amp;lt;=SCORING_DATE)) ;
set ABC&amp;amp;Start_d1. - ABC%sysfunc(&amp;amp;SCORING_DATE1., yymmddn8.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361528"&gt;@Shradha1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;I have datasets with their names indexed on date, say ABC_20210424,&amp;nbsp;ABC_20210425,&amp;nbsp;ABC_20210426 and so on.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Each dataset contains the same variables and one variable is Date. I have to use these datasets for a range of days, suppose from 15 APR 2021 to 30APR 2021 and within each dataset I want to select only those observations for which the Date variable takes value equal to the date indexed on the dataset name. For example,&amp;nbsp;ABC_20210424 dataset has a range of observations with varying dates, but I want to select only those observations where Date=20210424. How do I achieve this? I am trying the following piece of code but its giving the error:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;lt;LINE and COLUMN cannot be determined&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Code I am using:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;call symputx('Start_d11', put(intnx('month', today(),0), yymmddn8.));&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;call symputx('SCORING_DATE' , put(intnx('day', today(), -1, 's'), yymmddn8.));&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data ABCD&amp;amp;Start_d1. - ABCD&amp;amp;SCORING_DATE1.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (where("&amp;amp;Start_d11"d&amp;lt;=date&amp;lt;="&amp;amp;SCORING_DATE"d)) ;&lt;BR /&gt;set ABC&amp;amp;Start_d1. - ABC&amp;amp;SCORING_DATE1.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 16:12:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-date-variable-for-a-series-of-datasets/m-p/739547#M230840</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-06T16:12:11Z</dc:date>
    </item>
  </channel>
</rss>

