<?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 Converting date formats in in Sysfunc in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-date-formats-in-in-Sysfunc/m-p/841915#M332902</link>
    <description>&lt;P&gt;I am working to automate a piece of code. When I save my sas dataset I need to have the date the data was last refreshed attached to the end of the file name. Instead of changing the code every week to the new date I would rather just have it be automated. Here is what I have:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
	select max(date_created) as maxaddressdt 
	into :refresh separated by ""
	from mcir.new_address;
quit;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;refresh; */System returns 29OCT2022:05:45:08*/;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This returns the last refresh date in a date time format. I would like my file name to read as ARCHRP_20221029 for file organization purposes.&amp;nbsp; Below is what I tried to reformat the date time variable to be yymmddn8. The log gave the warning that Argument 2 is out of range.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let refreshfmt=%sysfunc(putc(&amp;amp;refresh,yymmddn8),8.) ;
%put &amp;amp;refreshfmt;


libname rawdata 'c:\data';
%macro saveloc(date=);
data rawdata.ArchRP&amp;amp;date (compress=binary);
	set rp;
run;
%mend saveloc;

%saveloc(date=&amp;amp;refreshfmt); 

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks for the help&lt;/P&gt;</description>
    <pubDate>Tue, 01 Nov 2022 17:11:54 GMT</pubDate>
    <dc:creator>OlsabeckT29</dc:creator>
    <dc:date>2022-11-01T17:11:54Z</dc:date>
    <item>
      <title>Converting date formats in in Sysfunc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-date-formats-in-in-Sysfunc/m-p/841915#M332902</link>
      <description>&lt;P&gt;I am working to automate a piece of code. When I save my sas dataset I need to have the date the data was last refreshed attached to the end of the file name. Instead of changing the code every week to the new date I would rather just have it be automated. Here is what I have:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
	select max(date_created) as maxaddressdt 
	into :refresh separated by ""
	from mcir.new_address;
quit;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;refresh; */System returns 29OCT2022:05:45:08*/;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This returns the last refresh date in a date time format. I would like my file name to read as ARCHRP_20221029 for file organization purposes.&amp;nbsp; Below is what I tried to reformat the date time variable to be yymmddn8. The log gave the warning that Argument 2 is out of range.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let refreshfmt=%sysfunc(putc(&amp;amp;refresh,yymmddn8),8.) ;
%put &amp;amp;refreshfmt;


libname rawdata 'c:\data';
%macro saveloc(date=);
data rawdata.ArchRP&amp;amp;date (compress=binary);
	set rp;
run;
%mend saveloc;

%saveloc(date=&amp;amp;refreshfmt); 

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks for the help&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 17:11:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-date-formats-in-in-Sysfunc/m-p/841915#M332902</guid>
      <dc:creator>OlsabeckT29</dc:creator>
      <dc:date>2022-11-01T17:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: Converting date formats in in Sysfunc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-date-formats-in-in-Sysfunc/m-p/841917#M332903</link>
      <description>&lt;P&gt;IMPORTANT POINT — do all date and time manipulations on numeric variables, not on character strings such as&amp;nbsp;29OCT2022:05:45:08&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next ... since you are using PROC SQL to extract the max DATE_CREATED (which is a numeric date/time value) just do the formatting there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lastly, to convert a date/time value (which is how DATE_CREATED is stored) to a formatted DATE value (which is what you want 20221029), use the DATEPART function and then format the result however you'd like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    select put(datepart(max(date_created)),yymmddn8.) into :refreshfmt from mcir.new_address;
quit;
%put &amp;amp;=refreshfmt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 17:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-date-formats-in-in-Sysfunc/m-p/841917#M332903</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-01T17:28:34Z</dc:date>
    </item>
  </channel>
</rss>

