<?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: Using a if and intnx date in another dataset in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Using-a-if-and-intnx-date-in-another-dataset/m-p/521227#M4173</link>
    <description>&lt;P&gt;You are not reading any data into your dataset A.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you just trying to make a dataset with only one observation based on the current date?&lt;/P&gt;
&lt;P&gt;Do you need that dataset for anything?&amp;nbsp; If not then put the logic into your query.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
  select *
  from A
  where month_dt= 
case when (day(today())&amp;gt;=5) then intnx('month',today(),0,'b')
else intnx('month',today(),-1,'b') end
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can eliminate the CASE and just use boolean logic to generate the proper offset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;month_dt = intnx('month',today(),0-(day(today())&amp;lt;5),'b')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your dataset is indexed on MONTH_DT then you might get better performance using macro code to make that date into a constant instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let today=%sysfunc(today());
%let cm=%sysfunc(intnx(month,&amp;amp;today,%eval(0-(%sysfunc(day(&amp;amp;today)))&amp;lt;5),b));
....
where month_dt = &amp;amp;cm 
....&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 13 Dec 2018 18:07:59 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-12-13T18:07:59Z</dc:date>
    <item>
      <title>Using a if and intnx date in another dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-a-if-and-intnx-date-in-another-dataset/m-p/521190#M4159</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the the current month date to refer to the prior months start date until 4th of the current month which I am able to do using the below code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; A;&lt;/P&gt;&lt;P&gt;format CM date9.;&lt;/P&gt;&lt;P&gt;if day(today())&amp;gt;=&lt;STRONG&gt;5&lt;/STRONG&gt; then CM=intnx('month',today(),&lt;STRONG&gt;0&lt;/STRONG&gt;,'b');&lt;/P&gt;&lt;P&gt;else CM=intnx('month',today(),-&lt;STRONG&gt;1&lt;/STRONG&gt;,'b');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once I get CM I want to be able to use it in another program where I will use it in the where clause&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table WANT as select * from A(a table in my library)&lt;/P&gt;&lt;P&gt;where month_dt= CM;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;If i write it this way, I get the errror that CM does not exist in A&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can this be done?&lt;/P&gt;&lt;P&gt;OR can CM be converted to a macro&amp;nbsp; so that it can be used in WANT ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot in advance!!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 16:45:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-a-if-and-intnx-date-in-another-dataset/m-p/521190#M4159</guid>
      <dc:creator>new_sas_user_4</dc:creator>
      <dc:date>2018-12-13T16:45:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using a if and intnx date in another dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-a-if-and-intnx-date-in-another-dataset/m-p/521197#M4162</link>
      <description>&lt;P&gt;1. Create a macro variable and use that in the query. There is no need to format the variable to appear as date9, that just makes it more complex.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;

format CM date9.;

if day(today())&amp;gt;=5 then CM=intnx('month',today(),0,'b');

else CM=intnx('month',today(),-1,'b');

 call symputx('cm', cm, 'g');

run;

%put &amp;amp;cm.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Use a SQL query to select. Note that I've changed table names from A to make it less confusing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select * from table1
where month_dt in (select cm from A);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/213838"&gt;@new_sas_user_4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the the current month date to refer to the prior months start date until 4th of the current month which I am able to do using the below code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; A;&lt;/P&gt;
&lt;P&gt;format CM date9.;&lt;/P&gt;
&lt;P&gt;if day(today())&amp;gt;=&lt;STRONG&gt;5&lt;/STRONG&gt; then CM=intnx('month',today(),&lt;STRONG&gt;0&lt;/STRONG&gt;,'b');&lt;/P&gt;
&lt;P&gt;else CM=intnx('month',today(),-&lt;STRONG&gt;1&lt;/STRONG&gt;,'b');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once I get CM I want to be able to use it in another program where I will use it in the where clause&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table WANT as select * from A(a table in my library)&lt;/P&gt;
&lt;P&gt;where month_dt= CM;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;If i write it this way, I get the errror that CM does not exist in A&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can this be done?&lt;/P&gt;
&lt;P&gt;OR can CM be converted to a macro&amp;nbsp; so that it can be used in WANT ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot in advance!!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 16:57:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-a-if-and-intnx-date-in-another-dataset/m-p/521197#M4162</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-12-13T16:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using a if and intnx date in another dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-a-if-and-intnx-date-in-another-dataset/m-p/521199#M4164</link>
      <description>&lt;P&gt;From the below program dataset A is generated but i dont see any SET statement to use the existing dataset. so i dont if the dataset A is actually created. please check, if it is then the proc sql should work if the month_dt is also available in dataset A along with date CM which you derived.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
set xxxx;?
format CM date9.;
if day(today())&amp;gt;=5 then CM=intnx('month',today(),0,'b');
else CM=intnx('month',today(),-1,'b');
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>Thu, 13 Dec 2018 16:59:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-a-if-and-intnx-date-in-another-dataset/m-p/521199#M4164</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-12-13T16:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using a if and intnx date in another dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-a-if-and-intnx-date-in-another-dataset/m-p/521227#M4173</link>
      <description>&lt;P&gt;You are not reading any data into your dataset A.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you just trying to make a dataset with only one observation based on the current date?&lt;/P&gt;
&lt;P&gt;Do you need that dataset for anything?&amp;nbsp; If not then put the logic into your query.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
  select *
  from A
  where month_dt= 
case when (day(today())&amp;gt;=5) then intnx('month',today(),0,'b')
else intnx('month',today(),-1,'b') end
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can eliminate the CASE and just use boolean logic to generate the proper offset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;month_dt = intnx('month',today(),0-(day(today())&amp;lt;5),'b')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your dataset is indexed on MONTH_DT then you might get better performance using macro code to make that date into a constant instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let today=%sysfunc(today());
%let cm=%sysfunc(intnx(month,&amp;amp;today,%eval(0-(%sysfunc(day(&amp;amp;today)))&amp;lt;5),b));
....
where month_dt = &amp;amp;cm 
....&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Dec 2018 18:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-a-if-and-intnx-date-in-another-dataset/m-p/521227#M4173</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-13T18:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using a if and intnx date in another dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-a-if-and-intnx-date-in-another-dataset/m-p/521231#M4174</link>
      <description>&lt;P&gt;Thanks everyone!!&lt;/P&gt;&lt;P&gt;I am sorry for the confusion with the table names..&lt;/P&gt;&lt;P&gt;The first table I create named A is just for creating the date and I want to use this date to filter from another table (lets call it X).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 18:23:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-a-if-and-intnx-date-in-another-dataset/m-p/521231#M4174</guid>
      <dc:creator>new_sas_user_4</dc:creator>
      <dc:date>2018-12-13T18:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using a if and intnx date in another dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-a-if-and-intnx-date-in-another-dataset/m-p/521232#M4175</link>
      <description>&lt;P&gt;Thanks a lot &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 18:25:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-a-if-and-intnx-date-in-another-dataset/m-p/521232#M4175</guid>
      <dc:creator>new_sas_user_4</dc:creator>
      <dc:date>2018-12-13T18:25:08Z</dc:date>
    </item>
  </channel>
</rss>

