<?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: Importing date files from excel (xlsx) to sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/707693#M217320</link>
    <description>&lt;P&gt;okay, I will try to search. Thanks a lot&lt;/P&gt;</description>
    <pubDate>Tue, 22 Dec 2020 15:58:09 GMT</pubDate>
    <dc:creator>Anita_n</dc:creator>
    <dc:date>2020-12-22T15:58:09Z</dc:date>
    <item>
      <title>Importing date files from excel (xlsx) to sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/707661#M217302</link>
      <description>&lt;P&gt;Hello all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;there are some set of data stressing me up. please help.&lt;/P&gt;
&lt;P&gt;Am tring to import a dataset into sas with date fields. In excel the date field is formated as date (04.06.2020)&lt;/P&gt;
&lt;P&gt;but when this is imported to sas it changes to character (2020-06-04). I have tried all possible means but it isn't&amp;nbsp;working.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hier test data :&lt;/P&gt;
&lt;P&gt;in excel (formatted as date)&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; in sas (changes to character)&lt;/P&gt;
&lt;P&gt;04.06.2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2020-06-04&lt;/P&gt;
&lt;P&gt;05.07.2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2020-07-05&lt;/P&gt;
&lt;P&gt;22.10.2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2019-10-22&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sas code1: 
proc import datafile= "mypath\myindat.xlsx" out= myoutdat 
dbms=xlsx replace;
run;


sas code2:

data patient;
%let _EFIERR_ = 0; 
infile "mypath\myindat.csv" delimiter = ';' MISSOVER DSD lrecl=13106 firstobs=1 ;
informat mydatvar mmddyy10.; format mydatvar mmddyy10.;
if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I will ne very grateful for any help&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2020 14:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/707661#M217302</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2020-12-22T14:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: Importing date files from excel (xlsx) to sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/707674#M217307</link>
      <description>&lt;P&gt;You need to provide more details or examples.&lt;/P&gt;
&lt;P&gt;Do you have actual EXCEL files as in your first SAS code fragment? Or just a text file as in your second SAS code fragment?&lt;/P&gt;
&lt;P&gt;If you are reading from an XLSX file then SAS will not convert dates in the way you show.&amp;nbsp; It will either read the dates properly or if the column in the XLSX file has mixed numeric and character values it might convert the dates into character strings that represent the number that EXCEL uses to store that date.&amp;nbsp; It the cells in the XLSX file are strings and not dates then their values will not change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are reading from a text file then just write your own data step to read the file and you can have complete control over how the dates are read and what format is attached to them to make them display in a human recognizable way.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2020 14:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/707674#M217307</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-22T14:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: Importing date files from excel (xlsx) to sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/707675#M217308</link>
      <description>&lt;P&gt;actually am reading from an xlsx datafile so the proc import is the one I used. Since it wasn't working properly, I converted the xlsx data to csv , but it didn't work either&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't really understand why sas converts the date fields to character. I checked the field there are only dates in there and they aren't mixed with characters.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2020 14:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/707675#M217308</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2020-12-22T14:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: Importing date files from excel (xlsx) to sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/707676#M217309</link>
      <description>&lt;P&gt;Run PROC CONTENTS on the SAS dataset created by the PROC IMPORT.&amp;nbsp; Are you sure you don't have a numeric variable that is being displayed with the YYMMDD10. format?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2020 14:59:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/707676#M217309</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-22T14:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Importing date files from excel (xlsx) to sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/707685#M217315</link>
      <description>&lt;P&gt;proc contents says the field is a character field&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Contents: Variablen" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="l data"&gt;Datum_FAX&lt;/TD&gt;
&lt;TD class="l data"&gt;Char&lt;/TD&gt;
&lt;TD class="r data"&gt;10&lt;/TD&gt;
&lt;TD class="l data"&gt;$10.&lt;/TD&gt;
&lt;TD class="l data"&gt;$10.&lt;/TD&gt;
&lt;TD class="l data"&gt;Datum_FAX&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 22 Dec 2020 15:27:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/707685#M217315</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2020-12-22T15:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: Importing date files from excel (xlsx) to sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/707691#M217319</link>
      <description>&lt;P&gt;So the column in the XLSX file is not numeric.&amp;nbsp; There is at least one cell in that column that does not have a number (both Excel and SAS store dates as number of days, they just use a different base date for counting).&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2020 15:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/707691#M217319</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-22T15:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: Importing date files from excel (xlsx) to sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/707693#M217320</link>
      <description>&lt;P&gt;okay, I will try to search. Thanks a lot&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2020 15:58:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/707693#M217320</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2020-12-22T15:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: Importing date files from excel (xlsx) to sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/708171#M217575</link>
      <description>&lt;P&gt;&lt;FONT face="helvetica"&gt;Hi, I was able to import some of the columns from excel to sas in the right format. I read a post which says for 32 bits sas dbms should be equal to excel so I changed my code to:&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile= "mypath\excelfile.xlsx" out= myoutfile
dbms=excel replace;
	GETNAMES=YES;
	MIXED=YES;
	SCANTEXT=YES;
	USEDATE=YES;
	SCANTIME=YES;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and&amp;nbsp;it&amp;nbsp;worked&amp;nbsp;worked&amp;nbsp;for&amp;nbsp;some&amp;nbsp;columns but for one particular column not.&lt;/P&gt;
&lt;P&gt;I&amp;nbsp;will&amp;nbsp;like&amp;nbsp;to&amp;nbsp;mention&amp;nbsp;that&amp;nbsp;this&amp;nbsp;column&amp;nbsp;is&amp;nbsp;a&amp;nbsp;calculated column&amp;nbsp;in excel.&amp;nbsp;In&amp;nbsp;sas&amp;nbsp;this&amp;nbsp;column&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is&amp;nbsp;imported&amp;nbsp;as&amp;nbsp;a&amp;nbsp;string. In excel the date is displayed as&amp;nbsp;&amp;nbsp;16.11.2018 (date format). In sas it's displayed as&amp;nbsp;&amp;nbsp;16.11.2018 (string $10.) I tried to use this code to convert the string back to date but it isn't working:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data newfile;
set oldfile;
format  stringdate ddmmyy10.;
run;


ERROR 48-59: Format $DDMMYY was not found or could not be loaded
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;please any help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Dec 2020 10:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/708171#M217575</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2020-12-25T10:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: Importing date files from excel (xlsx) to sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/708204#M217588</link>
      <description>&lt;P&gt;You can't apply a numeric date format to a character date string. You first need to convert the date string into a new numeric variable. Try using the INPUT function to do the conversion:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data newfile;
set oldfile;
numericdate = input(stringdate, ddmmyy10.);
format  numericdate ddmmyy10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Dec 2020 21:49:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/708204#M217588</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-12-25T21:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: Importing date files from excel (xlsx) to sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/708283#M217653</link>
      <description>&lt;P&gt;So it seems the formula is generating a string instead of a date value.&amp;nbsp; You can use the INPUT() function to convert the string to a date value.&amp;nbsp; But since the current variable is character you will need to make a new numeric variable.&amp;nbsp; Once you have a date value you can attach any date format.&amp;nbsp; Personally I prefer to use either DATE or YYMMDD format for dates to avoid the confusion that using D-M-Y order or M-D-Y order can generate.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;realdate= input(stringdate,ddmmyy10.);
format realdate date9.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to leave the variable as a string you could use INPUT() and PUT() together to generate a new string with a different way of presenting the date value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;stringdate=put(input(stringdate,ddmmyy10.),yymmdd10.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But note you might then lose any other type of data that might be in that character string.&amp;nbsp; Such as partial date indications like 'xx.01.2020'.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Dec 2020 16:57:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/708283#M217653</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-26T16:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: Importing date files from excel (xlsx) to sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/708335#M217677</link>
      <description>&lt;P&gt;Thanks to you for the tipps, unfornately it's still not working. I have decided to leave the issue till I get back to work after the holidays. The file is given me headache.&amp;nbsp; I will let you know if am able to fishout the cause of the problem. Thanks a lot.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Dec 2020 12:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/708335#M217677</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2020-12-27T12:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: Importing date files from excel (xlsx) to sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/708359#M217691</link>
      <description>&lt;P&gt;I also suggest you try saving your Excel worksheet as a CSV file as that will give you much better control over data types and formats.&lt;/P&gt;</description>
      <pubDate>Sun, 27 Dec 2020 21:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-date-files-from-excel-xlsx-to-sas/m-p/708359#M217691</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-12-27T21:48:25Z</dc:date>
    </item>
  </channel>
</rss>

