<?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: Convert datetime to char error in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544579#M7883</link>
    <description>&lt;P&gt;These are not ERRORs, these are NOTEs that inform you about implicit type conversions.&lt;/P&gt;
&lt;P&gt;By using call symputx() instead of call symput(), you can suppress those NOTEs:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symputx('dt','01JAN2019:00:00:00'dt);
run;

data _null_;
call symputx('FD',intnx('dtmonth',&amp;amp;dt,0,'B'));
call symputx('LD',intnx('dtmonth',&amp;amp;dt,0,'E'));
run;

data _null_;
call symputx('FD_new',put(datepart(&amp;amp;fd),datetime.));
call symputx('LD_new',put(datepart(&amp;amp;ld),datetime.));
run;

%put fd_new=&amp;amp;fd_new.;
%put ld_new=&amp;amp;ld_new.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;27         data _null_;
28         call symputx('dt','01JAN2019:00:00:00'dt);
29         run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

30         
31         data _null_;
32         call symputx('FD',intnx('dtmonth',&amp;amp;dt,0,'B'));
33         call symputx('LD',intnx('dtmonth',&amp;amp;dt,0,'E'));
34         run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

35         
36         data _null_;
37         call symputx('FD_new',put(datepart(&amp;amp;fd),datetime.));
38         call symputx('LD_new',put(datepart(&amp;amp;ld),datetime.));
39         run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

2                                                          Das SAS System                            07:11 Wednesday, March 20, 2019

40         
41         %put fd_new=&amp;amp;fd_new.;
fd_new=01JAN60:05:59:10
42         %put ld_new=&amp;amp;ld_new.;
ld_new=01JAN60:05:59:40
&lt;/PRE&gt;</description>
    <pubDate>Wed, 20 Mar 2019 14:08:38 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-03-20T14:08:38Z</dc:date>
    <item>
      <title>Convert datetime to char error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544487#M7859</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;i have this macro, it&amp;nbsp; works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   %macro date_loop(start,end);
   %let start=%sysfunc(inputn(&amp;amp;start,DATETIME16.));
   %let end=%sysfunc(inputn(&amp;amp;end,DATETIME16.));
   %let dif=%sysfunc(intck(HOUR,&amp;amp;start,&amp;amp;end));
     %do i=0 %to &amp;amp;dif;
      %let DATA_INIZIO=%sysfunc(intnx(HOUR,&amp;amp;start,&amp;amp;i,b),DATETIME16.);
	  %let DATA_FINE=%sysfunc(intnx(HOUR,"&amp;amp;DATA_INIZIO"dt,1),DATETIME16.);
      %put &amp;amp;DATA_INIZIO;

	  	  	PROC SQL ; /* ACCODO */ 
			CREATE TABLE  LDS.TORARIO_VUOTO_p  AS 
			
			SELECT 
			KEYATM,
			"&amp;amp;DATA_INIZIO"dt FORMAT=DATETIME16. AS   DATA_INIZIO,
			"&amp;amp;DATA_FINE"dt  FORMAT=DATETIME16. AS   DATA_FINE,

			 datepart("&amp;amp;DATA_INIZIO"dt ) FORMAT=DDMMYY10. AS Date,
			HOUR("&amp;amp;DATA_INIZIO"dt )   FORMAT=BEST12. AS Time,
			WEEKDAY( datepart("&amp;amp;DATA_INIZIO"dt ) ) FORMAT=BEST12. AS Day

			from LDS.TORARIO_ANAG A
			 WHERE KEYATM   = '020081319902752'
			;
			quit;


     %end;
   %mend date_loop;

   %date_loop(01FEB19:00:00:00,28FEB19:23:59:59);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But i need to insert into macro two variables for this value&amp;nbsp;fd = 01FEB19:00:00:00&amp;nbsp; &amp;nbsp;ld=28FEB19:23:59:59,&amp;nbsp;to determine automatically&lt;/P&gt;
&lt;P&gt;first and last hour of 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;data _null_;
dt = '01FEB2019:00:00:00'dt; 
fd = intnx('dtmonth', dt, 0, 'B');
ld = intnx('dtmonth', dt, 0, 'E');

fd= put(fd,datetime.);
ld= put(Ld,datetime.);
run;

%put NOTE: &amp;amp;fd &amp;amp;ld &amp;amp;dt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i have this error,&amp;nbsp;can you tell me what the error is in the format? thank's :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  data _null_;
197      dt = '01FEB2019:00:00:00'dt;
198      fd = intnx('dtmonth', dt, 0, 'B');
199      ld  = intnx('dtmonth', dt, 0, 'E');
200
201      fd= put(fd,datetime.);
202      ld= put(Ld,datetime.);
203  run;

NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      201:9   202:9
NOTE: Invalid numeric data, '01FEB19:00:00:00' , at line 201 column 9.
NOTE: Invalid numeric data, '28FEB19:23:59:59' , at line 202 column 9.
dt=1864598400 fd=. ld=. _ERROR_=1 _N_=1
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


204
205  %put NOTE: &amp;amp;fd &amp;amp;ld  &amp;amp;dt;
NOTE:            .            .    1861920000

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 09:36:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544487#M7859</guid>
      <dc:creator>Cello23</dc:creator>
      <dc:date>2019-03-20T09:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: Convert datetime to char error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544503#M7860</link>
      <description>&lt;P&gt;You override variables fd,ld .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
dt = '01FEB2019:00:00:00'dt; 
fd = intnx('dtmonth', dt, 0, 'B');
ld = intnx('dtmonth', dt, 0, 'E');

new_fd= put(fd,datetime.);
new_ld= put(Ld,datetime.);
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>Wed, 20 Mar 2019 10:54:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544503#M7860</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-03-20T10:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: Convert datetime to char error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544556#M7868</link>
      <description>&lt;P&gt;i tried but i have an error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    fd = intnx('dtmonth', &amp;amp;dt, 0, 'B');
    ld  = intnx('dtmonth', &amp;amp;dt, 0, 'E');
 
	fd_new= put(fd,datetime.);
	ld_new= put(Ld,datetime.);
	put fd_new d  ld_new;
run;

%put NOTE: &amp;amp;fd_new;
 
 
 
   %macro date_loop(start,end);
   %let start=%sysfunc(inputn(&amp;amp;start,DATETIME16.));
   %let end=%sysfunc(inputn(&amp;amp;end,DATETIME16.));
   %let dif=%sysfunc(intck(HOUR,&amp;amp;start,&amp;amp;end));
     %do i=0 %to &amp;amp;dif;
      %let DATA_INIZIO=%sysfunc(intnx(HOUR,&amp;amp;start,&amp;amp;i,b),DATETIME16.);
	  %let DATA_FINE=%sysfunc(intnx(HOUR,"&amp;amp;DATA_INIZIO"dt,1),DATETIME16.);
      %put &amp;amp;DATA_INIZIO;

	  	  	PROC SQL ; /* ACCODO */ 
			CREATE TABLE  LDS.TORARIO_VUOTO_p  AS 
			
			SELECT 
			KEYATM,
			"&amp;amp;DATA_INIZIO"dt FORMAT=DATETIME16. AS   DATA_INIZIO,
			"&amp;amp;DATA_FINE"dt  FORMAT=DATETIME16. AS   DATA_FINE,

			 datepart("&amp;amp;DATA_INIZIO"dt ) FORMAT=DDMMYY10. AS Date,
			HOUR("&amp;amp;DATA_INIZIO"dt )   FORMAT=BEST12. AS Time,
			WEEKDAY( datepart("&amp;amp;DATA_INIZIO"dt ) ) FORMAT=BEST12. AS Day

			from LDS.TORARIO_ANAG A
			 WHERE KEYATM   = '020081319902752'
			;
			quit;


     %end;
   %mend date_loop;

   %date_loop(&amp;amp;fd_new,&amp;amp;ld_new);&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Log error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;276  data _null_;
277      fd = intnx('dtmonth', &amp;amp;dt, 0, 'B');
278      ld  = intnx('dtmonth', &amp;amp;dt, 0, 'E');
279
280      fd_new= put(fd,datetime.);
281      ld_new= put(Ld,datetime.);
282      put fd_new d  ld_new;
283  run;

NOTE: Variable d is uninitialized.
01JAN19:00:00:00 . 31JAN19:23:59:59
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


WARNING: Apparent symbolic reference FD_NEW not resolved.
284
285  %put NOTE: &amp;amp;fd_new;
NOTE: &amp;amp;fd_new
286
287
288
289     %macro date_loop(start,end);
290     %let start=%sysfunc(inputn(&amp;amp;start,DATETIME16.));
291     %let end=%sysfunc(inputn(&amp;amp;end,DATETIME16.));
292     %let dif=%sysfunc(intck(HOUR,&amp;amp;start,&amp;amp;end));
293       %do i=0 %to &amp;amp;dif;
294        %let DATA_INIZIO=%sysfunc(intnx(HOUR,&amp;amp;start,&amp;amp;i,b),DATETIME16.);
295        %let DATA_FINE=%sysfunc(intnx(HOUR,"&amp;amp;DATA_INIZIO"dt,1),DATETIME16.);
296        %put &amp;amp;DATA_INIZIO;
297
298              PROC SQL ; /* ACCODO */
299              CREATE TABLE  LDS.TORARIO_VUOTO_p  AS
300
301              SELECT
302              KEYATM,
303              "&amp;amp;DATA_INIZIO"dt FORMAT=DATETIME16. AS   DATA_INIZIO,
304              "&amp;amp;DATA_FINE"dt  FORMAT=DATETIME16. AS   DATA_FINE,
305
306               datepart("&amp;amp;DATA_INIZIO"dt ) FORMAT=DDMMYY10. AS Date,
307              HOUR("&amp;amp;DATA_INIZIO"dt )   FORMAT=BEST12. AS Time,
308              WEEKDAY( datepart("&amp;amp;DATA_INIZIO"dt ) ) FORMAT=BEST12. AS Day
309
310              from LDS.TORARIO_ANAG A
311               WHERE KEYATM   = '020081319902752'
312              ;
313              quit;
314
315
316       %end;
317     %mend date_loop;
318
319     %date_loop(&amp;amp;fd_new,&amp;amp;ld_new);
WARNING: Apparent symbolic reference FD_NEW not resolved.
WARNING: Apparent symbolic reference LD_NEW not resolved.
WARNING: Apparent symbolic reference FD_NEW not resolved.
WARNING: Argument 1 to function INPUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is
         out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The
      result of the operations have been set to a missing value.
WARNING: Apparent symbolic reference LD_NEW not resolved.
WARNING: Argument 1 to function INPUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is
         out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The
      result of the operations have been set to a missing value.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
       operand is required. The condition was: &amp;amp;dif
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro DATE_LOOP will stop executing.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;thank's&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 13:30:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544556#M7868</guid>
      <dc:creator>Cello23</dc:creator>
      <dc:date>2019-03-20T13:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: Convert datetime to char error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544560#M7872</link>
      <description>&lt;P&gt;You are trying to reference a macro variable you never created.&lt;/P&gt;
&lt;P&gt;You can use CALL SYMPUTX() to create a macro variable in a data step.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 13:36:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544560#M7872</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-20T13:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: Convert datetime to char error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544566#M7875</link>
      <description>&lt;P&gt;i tried:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 		data _null_;
		call symput('dt', '01JAN2019:00:00:00'dt );
		run;

  		data _null_;
		 call symput('FD', intnx('dtmonth', &amp;amp;dt, 0, 'B') );
		 call symput('LD', intnx('dtmonth', &amp;amp;dt, 0, 'E') );
  		run;

  		data _null_;
		 call symput('FD_new', put(datepart(&amp;amp;fd),datetime.) );
		 call symput('LD_new', put(datepart(&amp;amp;ld),datetime.) );
  		run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;i have this error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;336
337
338          data _null_;
339          call symput('dt', '01JAN2019:00:00:00'dt );
340          run;

NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
      339:27
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


341
342          data _null_;
343           call symput('FD', intnx('dtmonth', &amp;amp;dt, 0, 'B') );
344           call symput('LD', intnx('dtmonth', &amp;amp;dt, 0, 'E') );
345          run;

NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
      343:28   344:28
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


346
347          data _null_;
348           call symput('FD_new', put(datepart(&amp;amp;fd),datetime.) );
349           call symput('LD_new', put(datepart(&amp;amp;ld),datetime.) );
350          run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;thank's!!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 13:44:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544566#M7875</guid>
      <dc:creator>Cello23</dc:creator>
      <dc:date>2019-03-20T13:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: Convert datetime to char error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544577#M7881</link>
      <description>&lt;P&gt;Why are you using the older call symput() function instead of the newer call symputx()?&amp;nbsp; Only use the older version if you need to have leading or trailing spaces written into the macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are you going to use these macro variables to do?&lt;/P&gt;
&lt;P&gt;If you are just going to use them to assign values or compare values there is no need to apply any format to them.&lt;/P&gt;
&lt;PRE&gt;202   data _null_;
203     call symputx('today',date());
204     call symputx('now',datetime());
205   run;

NOTE: DATA statement used (Total process time):
      real time           0.09 seconds
      cpu time            0.01 seconds


206   %put &amp;amp;=today &amp;amp;=now;
TODAY=21628 NOW=1868695382.4
207
208   data _null_;
209     if date()=&amp;amp;today then put 'It is today.';
210     if abs(datetime()-&amp;amp;now) &amp;lt; 60*60 then put 'It is within an hour of now.';
211   run;

It is today.
It is within an hour of now.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;If you do want to store the formatted value (a string instead of a number) into the macro variable then convert using the format. Make sure to use a format that is long enough to store the full four digits of the year.&amp;nbsp; But then if you want to use those values in your code you will need add quotes and suffix make valid date or datetime literal values.&lt;/P&gt;
&lt;PRE&gt;212   data _null_;
213     call symputx('today',put(date(),date9.));
214     call symputx('now',put(datetime(),datetime20.));
215   run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


216   %put &amp;amp;=today &amp;amp;=now;
TODAY=20MAR2019 NOW=20MAR2019:10:05:05
217
218   data _null_;
219     if date()="&amp;amp;today"d then put 'It is today.';
220     if abs(datetime()-"&amp;amp;now"dt) &amp;lt; 60*60 then put 'It is within an hour of now.';
221   run;

It is today.
It is within an hour of now.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 14:06:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544577#M7881</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-20T14:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: Convert datetime to char error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544579#M7883</link>
      <description>&lt;P&gt;These are not ERRORs, these are NOTEs that inform you about implicit type conversions.&lt;/P&gt;
&lt;P&gt;By using call symputx() instead of call symput(), you can suppress those NOTEs:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symputx('dt','01JAN2019:00:00:00'dt);
run;

data _null_;
call symputx('FD',intnx('dtmonth',&amp;amp;dt,0,'B'));
call symputx('LD',intnx('dtmonth',&amp;amp;dt,0,'E'));
run;

data _null_;
call symputx('FD_new',put(datepart(&amp;amp;fd),datetime.));
call symputx('LD_new',put(datepart(&amp;amp;ld),datetime.));
run;

%put fd_new=&amp;amp;fd_new.;
%put ld_new=&amp;amp;ld_new.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;27         data _null_;
28         call symputx('dt','01JAN2019:00:00:00'dt);
29         run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

30         
31         data _null_;
32         call symputx('FD',intnx('dtmonth',&amp;amp;dt,0,'B'));
33         call symputx('LD',intnx('dtmonth',&amp;amp;dt,0,'E'));
34         run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

35         
36         data _null_;
37         call symputx('FD_new',put(datepart(&amp;amp;fd),datetime.));
38         call symputx('LD_new',put(datepart(&amp;amp;ld),datetime.));
39         run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

2                                                          Das SAS System                            07:11 Wednesday, March 20, 2019

40         
41         %put fd_new=&amp;amp;fd_new.;
fd_new=01JAN60:05:59:10
42         %put ld_new=&amp;amp;ld_new.;
ld_new=01JAN60:05:59:40
&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Mar 2019 14:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544579#M7883</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-20T14:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: Convert datetime to char error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544593#M7887</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Using the modification you suggested, the result is not right,&amp;nbsp; fd_new = 01JAN60:05:59:10 and&amp;nbsp;ld_new =01JAN60:05:59:4 :&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;496&lt;BR /&gt;497 %put fd_new=&amp;amp;fd_new.;&lt;BR /&gt;fd_new=01JAN60:05:59:10&lt;BR /&gt;498 %put ld_new=&amp;amp;ld_new.;&lt;BR /&gt;ld_new=01JAN60:05:59:4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The result should be fd_new =&amp;nbsp;01JAN19:00:00:00&amp;nbsp; &amp;nbsp;(begin of month) and&amp;nbsp;ld_new =31JAN19:23:59:59 (end of month)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;thank's&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 14:50:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544593#M7887</guid>
      <dc:creator>Cello23</dc:creator>
      <dc:date>2019-03-20T14:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: Convert datetime to char error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544597#M7888</link>
      <description>&lt;P&gt;It sounds like your question is just how to generate macro variables with strings that LOOK LIKE datatime values?&lt;/P&gt;
&lt;P&gt;It is very easy to do.&lt;/P&gt;
&lt;P&gt;First you need to start with a value that is a valid datetime values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dt = '01FEB2019:00:00:00'dt; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can use INTNX() function.&amp;nbsp; Make sure to use a width on the format that is long enough that SAS will include 4 digits for the year. (Remember Y2K?)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let fd=%sysfunc(intnx(dtmonth,&amp;amp;dt,0,b),datetime20);
%let ld=%sysfunc(intnx(dtmonth,&amp;amp;dt,0,e),datetime20);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;251   %put &amp;amp;=dt;
DT='01FEB2019:00:00:00'dt
252   %put &amp;amp;=fd;
FD=01FEB2019:00:00:00
253   %put &amp;amp;=ld;
LD=28FEB2019:23:59:59
&lt;/PRE&gt;
&lt;P&gt;Notice how the new macro variables look different from the first one?&lt;/P&gt;
&lt;P&gt;If you want to use those values as datetime literals in your code then make sure to add the quotes and dt suffix.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let fd=%sysfunc(intnx(dtmonth,&amp;amp;dt,0,b),datetime20);
%let fd="&amp;amp;fd"dt;
%let ld=%sysfunc(intnx(dtmonth,&amp;amp;dt,0,e),datetime20);
%let ld="&amp;amp;ld"dt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;244   %put &amp;amp;=dt;
DT='01FEB2019:00:00:00'dt
245   %put &amp;amp;=fd;
FD="01FEB2019:00:00:00"dt
246   %put &amp;amp;=ld;
LD="28FEB2019:23:59:59"dt
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:09:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544597#M7888</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-20T15:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: Convert datetime to char error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544600#M7889</link>
      <description>&lt;P&gt;I mistakenly copied your wrong datepart() calls.&lt;/P&gt;
&lt;P&gt;Simplify the code to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dt='01JAN2019:00:00:00'dt;

data _null_;
call symputx('FD',put(intnx('dtmonth',&amp;amp;dt,0,'B'),datetime19.));
call symputx('LD',put(intnx('dtmonth',&amp;amp;dt,0,'E'),datetime19.));
run;

%put fd=&amp;amp;fd.;
%put ld=&amp;amp;ld.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;27         %let dt='01JAN2019:00:00:00'dt;
28         
29         data _null_;
30         call symputx('FD',put(intnx('dtmonth',&amp;amp;dt,0,'B'),datetime19.));
31         call symputx('LD',put(intnx('dtmonth',&amp;amp;dt,0,'E'),datetime19.));
32         run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

33         
34         %put fd=&amp;amp;fd.;
fd=01JAN2019:00:00:00
35         %put ld=&amp;amp;ld.;
ld=31JAN2019:23:59:59
&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:13:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/544600#M7889</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-20T15:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: Convert datetime to char error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/545716#M8063</link>
      <description>&lt;P&gt;Tom and &amp;nbsp;&lt;A class="lia-link-navigation lia-page-link lia-user-name-link" id="link_48" style="color: rgb(0, 153, 153);" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562" target="_self"&gt;&lt;SPAN class="login-bold"&gt;KurtBremser&lt;/SPAN&gt;&lt;/A&gt;&amp;nbsp;, your &lt;SPAN&gt;answers will solve my problem, thank's so much!!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 09:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Convert-datetime-to-char-error/m-p/545716#M8063</guid>
      <dc:creator>Cello23</dc:creator>
      <dc:date>2019-03-25T09:22:20Z</dc:date>
    </item>
  </channel>
</rss>

