<?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: Issue with string to date type conversion in proc sql statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-string-to-date-type-conversion-in-proc-sql-statement/m-p/746717#M234278</link>
    <description>&lt;P&gt;Pretty simple; See below.&lt;BR /&gt;Earlier it was a variable of type character and now numeric.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
Format date mmddyyd10.;
filenamenosuff='6-8-2021';
date=input(filenamenosuff,Anydtdte10.);
put date= ;
run;&lt;BR /&gt;/*&amp;nbsp;&lt;SPAN&gt; date=06-08-2021&lt;/SPAN&gt;&lt;BR /&gt;*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 09 Jun 2021 11:53:35 GMT</pubDate>
    <dc:creator>Sajid01</dc:creator>
    <dc:date>2021-06-09T11:53:35Z</dc:date>
    <item>
      <title>Issue with string to date type conversion in proc sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-string-to-date-type-conversion-in-proc-sql-statement/m-p/746607#M234215</link>
      <description>&lt;P&gt;Hello, I have written a program that imports multiple CSV files in a directory and merges them all into one SAS data file.&amp;nbsp; I think I have that part working properly.&amp;nbsp; However, one of the things I need to do is&amp;nbsp; and create a new column in the destination merged data set that takes the date in the file name being imported (example file name: 6-8-2021.csv) and stores that value into a new column.&amp;nbsp; I have been able to strip the ".csv" from the file name.&amp;nbsp; My issue is that when I try to convert the newly stripped file name (e.g. 6-8-2021) to a date format, it doesn't work properly.&amp;nbsp; I have tried multiple different syntaxes, but I must be making a silly mistake.&amp;nbsp; I suspect something has to do with the fact that my filenames don't have leading zeroes for single digit months or days.&lt;/P&gt;&lt;P&gt;The program is below.&amp;nbsp; The PROC SQL update statement is where I'm trying to do what I indicated above. I have tried using PUT and INPUT, but was always under the impression that PUT always creates string variable, so I abandoned that.&amp;nbsp; Right now, this program inserts nothing into the column.&amp;nbsp; Any assistance would be greatly appreciated.&amp;nbsp; Thanks so much. (I've attached the two files I'm trying to import as a proof of concept)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MultImp(dir=,out=);

%let rc=%str(%'dir %")&amp;amp;dir.%str(\%" /A-D/B/ON%');
filename myfiles pipe %unquote(&amp;amp;rc);

data list;
length fname $256.;
infile myfiles truncover;
input myfiles $100.;

fname=quote(upcase(cats("&amp;amp;dir",'\',myfiles)));
filenamenosuff = tranwrd(myfiles,'.csv','');
putlog 'WARNING: the filename is ' filenamenosuff=;
out="&amp;amp;out";
drop myfiles;
call execute('
  proc import dbms=csv out= _test
            datafile= '||fname||' replace ;
  run;
    proc append data=_test base='||out||' force; run;
 	proc delete data=_test; run;
	proc sql; alter table sasdata.merged add FNDate num format=mmddyyd10.; quit;
	proc sql; update sasdata.merged set FNDate = '||input(filenamenosuff,mmddyyd10.)||' where FNDate IS NULL; quit;
');
run;
filename myfiles clear;

%mend;

%MultImp(dir=C:\Users\micha\Desktop\rand,out=sasdata.merged);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 22:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-string-to-date-type-conversion-in-proc-sql-statement/m-p/746607#M234215</guid>
      <dc:creator>msale1</dc:creator>
      <dc:date>2021-06-08T22:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with string to date type conversion in proc sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-string-to-date-type-conversion-in-proc-sql-statement/m-p/746623#M234223</link>
      <description>&lt;P&gt;Did you look at the LOG?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
filenamenosuff='6-8-2021';
date=input(filenamenosuff,mmddyyd10.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;produces this log&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; 73         data a;
 74         filenamenosuff='6-8-2021';
 75         date=input(filenamenosuff,mmddyyd10.);
                                      __________
                                      485
 NOTE 485-185: Informat MMDDYYD was not found or could not be loaded.
 
 76         run;&lt;/PRE&gt;
&lt;P&gt;I think that's pretty clear. The informat MMDDYYD does not exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use informat MMDDYY&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 23:25:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-string-to-date-type-conversion-in-proc-sql-statement/m-p/746623#M234223</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-08T23:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with string to date type conversion in proc sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-string-to-date-type-conversion-in-proc-sql-statement/m-p/746636#M234235</link>
      <description>&lt;P&gt;Hello&lt;BR /&gt;This is one way to get the date in the desired format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
filenamenosuff='6-8-2021';
date=put(input(filenamenosuff,Anydtdte10.),mmddyyd10.);
put date= ;
run;
/* you will see this in the log 
date=06-08-2021 */&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Jun 2021 01:16:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-string-to-date-type-conversion-in-proc-sql-statement/m-p/746636#M234235</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-06-09T01:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with string to date type conversion in proc sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-string-to-date-type-conversion-in-proc-sql-statement/m-p/746654#M234249</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/131732"&gt;@Sajid01&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;BR /&gt;This is one way to get the date in the desired format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
filenamenosuff='6-8-2021';
date=put(input(filenamenosuff,Anydtdte10.),mmddyyd10.);
put date= ;
run;
/* you will see this in the log 
date=06-08-2021 */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But you don't create a date-variable, but a string looking like a one.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jun 2021 05:16:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-string-to-date-type-conversion-in-proc-sql-statement/m-p/746654#M234249</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-06-09T05:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with string to date type conversion in proc sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-string-to-date-type-conversion-in-proc-sql-statement/m-p/746717#M234278</link>
      <description>&lt;P&gt;Pretty simple; See below.&lt;BR /&gt;Earlier it was a variable of type character and now numeric.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
Format date mmddyyd10.;
filenamenosuff='6-8-2021';
date=input(filenamenosuff,Anydtdte10.);
put date= ;
run;&lt;BR /&gt;/*&amp;nbsp;&lt;SPAN&gt; date=06-08-2021&lt;/SPAN&gt;&lt;BR /&gt;*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jun 2021 11:53:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-string-to-date-type-conversion-in-proc-sql-statement/m-p/746717#M234278</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-06-09T11:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with string to date type conversion in proc sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-string-to-date-type-conversion-in-proc-sql-statement/m-p/746766#M234292</link>
      <description>&lt;P&gt;So you basically want to read all csv files in a directory into one dataset?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jun 2021 14:35:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-string-to-date-type-conversion-in-proc-sql-statement/m-p/746766#M234292</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-09T14:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with string to date type conversion in proc sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-string-to-date-type-conversion-in-proc-sql-statement/m-p/747541#M234637</link>
      <description>Thank you for your assistance. This worked. I must have been looking at the wrong date format lists.</description>
      <pubDate>Sat, 12 Jun 2021 15:15:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-string-to-date-type-conversion-in-proc-sql-statement/m-p/747541#M234637</guid>
      <dc:creator>msale1</dc:creator>
      <dc:date>2021-06-12T15:15:20Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with string to date type conversion in proc sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-string-to-date-type-conversion-in-proc-sql-statement/m-p/747542#M234638</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/96868"&gt;@msale1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you for your assistance. This worked. I must have been looking at the wrong date format lists.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your were looking a FORMAT list instead of looking at an INFORMAT list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FORMAT is used to convert values to text.&lt;/P&gt;
&lt;P&gt;INFORMAT is used to convert text to values.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Jun 2021 15:20:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-string-to-date-type-conversion-in-proc-sql-statement/m-p/747542#M234638</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-12T15:20:24Z</dc:date>
    </item>
  </channel>
</rss>

