<?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: Date variable is always converted to 01/01/1960 value. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-variable-is-always-converted-to-01-01-1960-value/m-p/305488#M65170</link>
    <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;file_received_dt= mdy(mon,day,year);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 18 Oct 2016 18:55:32 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2016-10-18T18:55:32Z</dc:date>
    <item>
      <title>Date variable is always converted to 01/01/1960 value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variable-is-always-converted-to-01-01-1960-value/m-p/305485#M65169</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am macro date variable is always converted to 01/01/1960, In the below &lt;FONT color="#FF0000"&gt;Received_date&lt;/FONT&gt; is the variable where I am tryng to assign the macro variable. &lt;FONT color="#FF0000"&gt;&amp;amp;file_dt&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename fnames pipe 'ls /usr/path/*.xlsx';


data fnames;
    infile fnames pad missover;
    input @1 filename $255.;
	year = scan(filename, -2);
	day = scan(filename, -3);
	mon = substr(scan(filename, -4),1,3);
	con = catx("/",day,mon,year);
   file_received_dt=input(catx("/",day,mon,year),date11.);
   format file_received_dt mmddyy10.;
    n=_n_;
run;

proc sql noprint; select count(filename) into :num from fnames; quit;

%macro file_process;
    %do i=3 %to &amp;amp;num;

        proc sql noprint;
            select strip(filename),file_received_dt into :filename, :file_received_dt  from fnames where n=&amp;amp;i;
        quit;

	%let file_proc = &amp;amp;filename;
	%let file_dt = &amp;amp;file_received_dt;

	libname xlsFile XLSX "&amp;amp;file_proc";
	options validvarname=v7;
	options SYMBOLGEN MPRINT;
	
	PROC SQL;
    	create table  work.data_raw as 
	(select * from xlsFile.'Sheet1$A3:AD2000'n where col1 is not null);
	quit;
	data work.data(rename=(number=number_1));
	set work.data_raw;
	if find(dob,".") Then 
	do;
	dob = substr(dob,1,6);
	end;
	if length(dob) &amp;gt;= 10 Then 
	do;
	format dob_Dt mmddyy10.;
	dob_Dt = dob;
	end;
	else
	do;
	dob_Dt = substr(dob,1,6) - 21916;
	 format dob_Dt mmddyy10.; 
	end;
	format Load_dt mmddyy10.;
	format Received_dt mmddyy10.;
	data_dt = put((INTNX('month', %sysfunc(today()), -2, 'B')),monyy5.);
	Load_dt = Today();

	Received_dt = &amp;amp;file_dt;

	sam_mod = put(sam, $8.);
	track_num_mod = input(col1, 8.);
	run;

	data work.data1(drop= col1 dob);
	set work.data;
	run;

	PROC SQL;
    	create table  work.data_raw_2 as 
	(select * from xlsFile.'transmittal tab$A3:L2000'n);
	quit;
	data work.data2;
	set work.data_raw_2;
	format Load_dt mmddyy10.;
	format Received_dt mmddyy10.;
	data_dt = put((INTNX('month', %sysfunc(today()), -2, 'B')),monyy5.);
	Load_dt = Today();

	Received_dt =&amp;amp;file_dt;

	run;
    %end;
%mend;

%file_process;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Oct 2016 19:39:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variable-is-always-converted-to-01-01-1960-value/m-p/305485#M65169</guid>
      <dc:creator>jayakumarmm</dc:creator>
      <dc:date>2016-10-18T19:39:17Z</dc:date>
    </item>
    <item>
      <title>Re: Date variable is always converted to 01/01/1960 value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variable-is-always-converted-to-01-01-1960-value/m-p/305488#M65170</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;file_received_dt= mdy(mon,day,year);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Oct 2016 18:55:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variable-is-always-converted-to-01-01-1960-value/m-p/305488#M65170</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2016-10-18T18:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: Date variable is always converted to 01/01/1960 value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variable-is-always-converted-to-01-01-1960-value/m-p/305490#M65171</link>
      <description>I have tried this but it is not working.I am able to get the exact value in macro variable &amp;amp;file_dt with my earlier code itself but when I try assign to a variable (Received_dt) it is breaking.</description>
      <pubDate>Tue, 18 Oct 2016 19:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variable-is-always-converted-to-01-01-1960-value/m-p/305490#M65171</guid>
      <dc:creator>jayakumarmm</dc:creator>
      <dc:date>2016-10-18T19:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: Date variable is always converted to 01/01/1960 value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variable-is-always-converted-to-01-01-1960-value/m-p/305512#M65176</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;file_received_dt&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;cats&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;day&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;mon&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;year&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;date9&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 19:43:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variable-is-always-converted-to-01-01-1960-value/m-p/305512#M65176</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-10-18T19:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: Date variable is always converted to 01/01/1960 value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variable-is-always-converted-to-01-01-1960-value/m-p/305514#M65177</link>
      <description>&lt;P&gt;Please supply some examples of the filenames you are trying to read.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 19:45:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variable-is-always-converted-to-01-01-1960-value/m-p/305514#M65177</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2016-10-18T19:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: Date variable is always converted to 01/01/1960 value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variable-is-always-converted-to-01-01-1960-value/m-p/305587#M65201</link>
      <description>&lt;P&gt;Look at the log at check for messages concerning automatic type conversion, missing values and the like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add put and %put statements at the crucial points in your code to verify that data step and macro variables contain exactly what you expected.&lt;/P&gt;
&lt;P&gt;Be aware that a put in a data step with lots of iterations/observation might fatally swamp your log, so test first with a small sample set.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 06:08:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variable-is-always-converted-to-01-01-1960-value/m-p/305587#M65201</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-19T06:08:19Z</dc:date>
    </item>
    <item>
      <title>Re: Date variable is always converted to 01/01/1960 value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variable-is-always-converted-to-01-01-1960-value/m-p/305645#M65211</link>
      <description>Filenames are like "log response September 20 2016.xlsx"</description>
      <pubDate>Wed, 19 Oct 2016 12:47:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variable-is-always-converted-to-01-01-1960-value/m-p/305645#M65211</guid>
      <dc:creator>jayakumarmm</dc:creator>
      <dc:date>2016-10-19T12:47:39Z</dc:date>
    </item>
    <item>
      <title>Re: Date variable is always converted to 01/01/1960 value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variable-is-always-converted-to-01-01-1960-value/m-p/305648#M65212</link>
      <description>&lt;P&gt;Before I'd go ANY farther with this, I'd make reasonable filenames mandatory. Anybody who uses a date format like that in an IT context is in dire need of being the target of a &lt;A href="http://www.catb.org/jargon/html/L/LART.html" target="_blank"&gt;LART&lt;/A&gt;. And get rid of the stupid blanks, there's underlines for that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As it is, I'd first do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename = scan(filename,1,'.');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to remove the extension.&lt;/P&gt;
&lt;P&gt;Then&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;year = input(scan(filename,-1,' '),4.);
day = input(scan(filename,-2,' '),2.);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For the month, I'd create a custom infomat that converts the textual month names to the numbers:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
invalue inmonth
  'January' = 1
  'February' = 2
....
  'September' = 9
...
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then use that in&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;month = input(scan(filename,-3,' '),inmonth.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;After that, use the mdy() function to build a date.&lt;/P&gt;
&lt;P&gt;All that would not be necessary if some &amp;amp;?%!?# had used a yyyy-mm-dd format for the date in the filename.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 13:14:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variable-is-always-converted-to-01-01-1960-value/m-p/305648#M65212</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-19T13:14:42Z</dc:date>
    </item>
  </channel>
</rss>

