<?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 change date format in macro &amp;amp;let in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776421#M246936</link>
    <description>&lt;P&gt;See a quick, simplified example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date1 :yymmdd10. date2:yymmdd10.;
format date1 date2 yymmdd10.;
datalines;
2021-10-26 2021-10-01
;

%let date_dly = 26oct2021;
%let gv_date_dly = %sysevalf("&amp;amp;date_dly."d);
%let first_day = %sysfunc(intnx(month,%sysfunc(today()),0,b));

proc sql;
select * from have
where date1 = &amp;amp;gv_date_dly. and date2 = &amp;amp;first_day.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have corrected the single to double quotes and checked the issue I mentioned in the other post, it comes down to which dates you get from the DATEPART function in your condition.&lt;/P&gt;
&lt;P&gt;If date_danych is already a date, then using the DATEPART function will always result in a date of 1960-01-01 (or 1959-12-31 for dates before 1960), as DATEPART is intended to convert counts of seconds to counts of days (roughly, doing a division by 86400).&lt;/P&gt;</description>
    <pubDate>Tue, 26 Oct 2021 10:17:09 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-10-26T10:17:09Z</dc:date>
    <item>
      <title>How to change date format in macro &amp;let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776408#M246925</link>
      <description>&lt;P&gt;I have a macro that I want to put in the where query, but I don't find the results, I think because my dates have the same format as in the picture below, how to transform the first_day macro to select the first day of the month, e.g. from the current month&lt;/P&gt;
&lt;PRE&gt;%let gv_date_dly=%sysevalf(%bquote('&amp;amp;date_dly.'d));
%let thismonth=%sysfunc(putn(%sysfunc(today()),yymmn10.));
%let first_day = %sysfunc(intnx(month,%sysfunc(today()),0,b))

proc sql;

	create table PolisyEnd as 

	select
	datepart(t1.data_danych)  as DATA_DANYCH format yymmdd10.
	,t1.obj_oid
	,t1.PRP_AGREEMENT				 
	,t1.PRP_POLICYNUMBER
	,t1.PRP_SOCIETY_PID
	,t1.PRP_END_DATE 				as PRP_END_DATE
	from 
		cmz.WMDTZDP_BH as t1
        where datepart(t1.data_danych) = &amp;amp;first_day. 
		and datepart(t1.data_danych) = &amp;amp;gv_date_dly.
;
quit;&lt;/PRE&gt;
&lt;P&gt;When I leave the where gv_data condition alone, it will find the dates for me, but as it adds first_day. I have a problem and it shows me empty results. How do I change macro &amp;amp; let first_day to show this date format&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Gieorgie_0-1635239727966.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65029i2B983DB8825B77FE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Gieorgie_0-1635239727966.png" alt="Gieorgie_0-1635239727966.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 09:15:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776408#M246925</guid>
      <dc:creator>Gieorgie</dc:creator>
      <dc:date>2021-10-26T09:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format in macro &amp;let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776411#M246928</link>
      <description>&lt;P&gt;A date is a date is a date. For comparisons, the format is IRRELEVANT(!!), as the raw values are compared.&lt;/P&gt;
&lt;P&gt;So you either have something that isn't really a SAS date, or you have no matches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does PROC CONTENTS say about&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data_danych&lt;/PRE&gt;
&lt;P&gt;in your dataset? And what values appear when you run PROC FREQ on that variable?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 09:43:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776411#M246928</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-26T09:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format in macro &amp;let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776413#M246930</link>
      <description>&lt;P&gt;What is the "date_dly" ? Is it standard 26oct2021 ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Single quotes in the:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let gv_date_dly=%sysevalf('&amp;amp;date_dly.'d);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;stops date_dly from resolving. If you run:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let gv_date_dly=%sysevalf('&amp;amp;date_dly.'d);
%let thismonth=%sysfunc(putn(%sysfunc(today()),yymmn10.));
%let first_day = %sysfunc(intnx(month,%sysfunc(today()),0,b));

%put _user_;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you will see an error in the log and null value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(off topic, the&amp;nbsp; "DATA_DANYCH" - sounds Polish, maybe write on PolSUG group [&amp;nbsp;&lt;A href="https://communities.sas.com/polsug" target="_blank"&gt;https://communities.sas.com/polsug&lt;/A&gt; ]?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 09:49:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776413#M246930</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-10-26T09:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format in macro &amp;let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776416#M246932</link>
      <description>data_dly is standard 26oct2021 . And when i put on where query i got result, but i need find range from dataset. Always start date its first day of current month . And i have problem with macro &amp;amp;First_day</description>
      <pubDate>Tue, 26 Oct 2021 09:58:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776416#M246932</guid>
      <dc:creator>Gieorgie</dc:creator>
      <dc:date>2021-10-26T09:58:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format in macro &amp;let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776418#M246934</link>
      <description>&lt;P&gt;This condition&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where datepart(t1.data_danych) = &amp;amp;first_day. 
		and datepart(t1.data_danych) = &amp;amp;gv_date_dly.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will only be true if both macro variables contain the &lt;U&gt;same&lt;/U&gt; value, and it matches a dataset value.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 10:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776418#M246934</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-26T10:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format in macro &amp;let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776420#M246935</link>
      <description>3&lt;BR /&gt;DATA_DANYCH Num 8 DATETIME20. DATETIME20. DATA_DANYCH</description>
      <pubDate>Tue, 26 Oct 2021 10:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776420#M246935</guid>
      <dc:creator>Gieorgie</dc:creator>
      <dc:date>2021-10-26T10:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format in macro &amp;let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776421#M246936</link>
      <description>&lt;P&gt;See a quick, simplified example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date1 :yymmdd10. date2:yymmdd10.;
format date1 date2 yymmdd10.;
datalines;
2021-10-26 2021-10-01
;

%let date_dly = 26oct2021;
%let gv_date_dly = %sysevalf("&amp;amp;date_dly."d);
%let first_day = %sysfunc(intnx(month,%sysfunc(today()),0,b));

proc sql;
select * from have
where date1 = &amp;amp;gv_date_dly. and date2 = &amp;amp;first_day.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have corrected the single to double quotes and checked the issue I mentioned in the other post, it comes down to which dates you get from the DATEPART function in your condition.&lt;/P&gt;
&lt;P&gt;If date_danych is already a date, then using the DATEPART function will always result in a date of 1960-01-01 (or 1959-12-31 for dates before 1960), as DATEPART is intended to convert counts of seconds to counts of days (roughly, doing a division by 86400).&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 10:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776421#M246936</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-26T10:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format in macro &amp;let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776422#M246937</link>
      <description>&lt;P&gt;See an adapted example of my code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date1 :e8601dt19. date2 :e8601dt19.;
format date1 date2 e8601dt19.;
datalines;
2021-10-26T05:23:22 2021-10-01T01:02:03
;

%let date_dly = 26oct2021;
%let gv_date_dly = %sysevalf("&amp;amp;date_dly."d);
%let first_day = %sysfunc(intnx(month,%sysfunc(today()),0,b));

proc sql;
select * from have
where datepart(date1) = &amp;amp;gv_date_dly. and datepart(date2) = &amp;amp;first_day.;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you still need to fix the issue (in your code) that a single variable can't be equal to two different values at the same time.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 10:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776422#M246937</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-26T10:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format in macro &amp;let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776474#M246968</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/401093"&gt;@Gieorgie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;3&lt;BR /&gt;DATA_DANYCH Num 8 DATETIME20. DATETIME20. DATA_DANYCH&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So you need to compare the values in that variable to a DATETIME value (number of seconds) not a DATE value (number of days).&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 13:22:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-date-format-in-macro-amp-let/m-p/776474#M246968</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-10-26T13:22:19Z</dc:date>
    </item>
  </channel>
</rss>

