<?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: Need help with data filter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-data-filter/m-p/874204#M345365</link>
    <description>&lt;P&gt;I would discourage using&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %let DateFrom = ‘01nov2022’;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;for macrovar datefrom.&amp;nbsp; Instead consider dropping the quotes, as in&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %let DateFrom = 01nov2022 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can use a filter such as&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where date &amp;gt;= "&amp;amp;datefrom"d &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Date literals like '01nov2022'd and "01nov2022"d have identical underlying date values.&amp;nbsp; &amp;nbsp;But using single quotes with a macrovariable inside the quotes (as in '&amp;amp;datefrom'd) would prevent the macro processor from resolving &amp;amp;datefrom to 01nov2022, while double quotes (as in "&amp;amp;datefrom"d) will support resolution of the macrovar DATEFROM.&lt;/P&gt;</description>
    <pubDate>Fri, 05 May 2023 19:20:48 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2023-05-05T19:20:48Z</dc:date>
    <item>
      <title>Need help with data filter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-data-filter/m-p/874188#M345361</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;Hey everyone, I could use some help with a query. Im using sas studio but without much knowledge from sql. I can read and understand what it does, thats about it.&lt;/P&gt;&lt;P&gt;My query contains several filters with the same date, so in my previous program sas eg I used a prompt to set this date once, and it would be used throughout the entire flow. If i wanted to change this date I could just adjust this value instead of going through the set finding all the date filters.&lt;/P&gt;&lt;P&gt;Now someone told me I can do about the same in sas studio, by creating a program that says:&lt;/P&gt;&lt;P&gt;%global DateFrom %let DateFrom = ‘01nov2022’&lt;/P&gt;&lt;P&gt;And in the queries I could just filter on the name Datefrom.&lt;/P&gt;&lt;P&gt;I also tried &amp;amp;Datefrom because this is what I used in sas eg.&lt;/P&gt;&lt;P&gt;This isn’t working at the moment, could someone guide me in the right direction. Preferably by using the dropdown menu’s as filter, not by using code.&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 05 May 2023 18:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-data-filter/m-p/874188#M345361</guid>
      <dc:creator>pikardenz</dc:creator>
      <dc:date>2023-05-05T18:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with data filter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-data-filter/m-p/874190#M345362</link>
      <description>&lt;P&gt;Note the syntax corrections here and the straight quotes rather than curly quotes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global DateFrom;
%let DateFrom = '01nov2022'd;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But of course, it would really help to see where and how you intend to use the DATEFROM macro variable. Please show us.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 18:35:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-data-filter/m-p/874190#M345362</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-05T18:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with data filter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-data-filter/m-p/874195#M345363</link>
      <description>&lt;P&gt;You did not include the semicolons to end your statements. So your code should look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global DateFrom;
%let DateFrom = '01nov2022' ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You don't really need the first one since you are NOT running the code inside a macro.&lt;/P&gt;
&lt;P&gt;If you want to use &amp;amp;DATEFROM as an actual DATE value then you should probably set the value to a date literal instead of character literal.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let DateFrom = '01nov2022'd ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Let's make some sample data we can try it out on.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
  do week=0 to 10;
    date=intnx('week','01OCT2022'd,week,'same');
    output;
  end;
 format date date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1683311664391.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83656i65495CF1A91380E9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1683311664391.png" alt="Tom_0-1683311664391.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Now we can use the macro variable in a WHERE statement (that is an easy way to "filter" in SAS code).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=example;
  where date &amp;gt; &amp;amp;datefrom;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_1-1683311735612.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83657iC34A8964641E2585/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_1-1683311735612.png" alt="Tom_1-1683311735612.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;We can do the same thing using the filter open when browsing a dataset in SAS/Studio&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_2-1683311805492.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83658iAB54FDFA205465F4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_2-1683311805492.png" alt="Tom_2-1683311805492.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_3-1683311826105.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83659i813FFBB9A5635777/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_3-1683311826105.png" alt="Tom_3-1683311826105.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 18:37:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-data-filter/m-p/874195#M345363</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-05T18:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with data filter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-data-filter/m-p/874204#M345365</link>
      <description>&lt;P&gt;I would discourage using&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %let DateFrom = ‘01nov2022’;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;for macrovar datefrom.&amp;nbsp; Instead consider dropping the quotes, as in&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %let DateFrom = 01nov2022 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can use a filter such as&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where date &amp;gt;= "&amp;amp;datefrom"d &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Date literals like '01nov2022'd and "01nov2022"d have identical underlying date values.&amp;nbsp; &amp;nbsp;But using single quotes with a macrovariable inside the quotes (as in '&amp;amp;datefrom'd) would prevent the macro processor from resolving &amp;amp;datefrom to 01nov2022, while double quotes (as in "&amp;amp;datefrom"d) will support resolution of the macrovar DATEFROM.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 19:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-data-filter/m-p/874204#M345365</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-05-05T19:20:48Z</dc:date>
    </item>
  </channel>
</rss>

