<?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: How to specify formats when importing data from Excel in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/916258#M360929</link>
    <description>&lt;P&gt;Hi Kurt,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for pointing that out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since R (&lt;A href="https://readxl.tidyverse.org/articles/cell-and-column-types.html" target="_blank"&gt;Cell and Column Types • readxl (tidyverse.org)&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;library(readxl)
read_excel("yo.xlsx", col_types = c("date", "skip", "guess", "numeric"))&lt;/PRE&gt;&lt;P&gt;or Python (&lt;A href="https://stackoverflow.com/questions/32591466/python-pandas-how-to-specify-data-types-when-reading-an-excel-file" target="_blank"&gt;Python pandas: how to specify data types when reading an Excel file? - Stack Overflow&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import pandas as pd
df = pd.read_excel('Book1.xlsx',sheetname='Sheet1',header=0,converters={'names':str,'ages':str})&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;are both capable of handling excel data for professional purposes, I will prefer to use those for the required task.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks and BR&lt;/P&gt;&lt;P&gt;Lukas&lt;/P&gt;</description>
    <pubDate>Thu, 15 Feb 2024 05:51:17 GMT</pubDate>
    <dc:creator>LuGa</dc:creator>
    <dc:date>2024-02-15T05:51:17Z</dc:date>
    <item>
      <title>How to specify formats when importing data from Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/915505#M360743</link>
      <description>&lt;P&gt;Dear SAS community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;According to :&lt;/P&gt;&lt;P&gt;&lt;A href="https://support.sas.com/kb/15/778.html" target="_blank" rel="noopener"&gt;15778 - How to specify formats when importing data from Excel (sas.com)&lt;/A&gt;&lt;BR /&gt;proc import should allow specifying formats for imports.&lt;/P&gt;&lt;P&gt;However the statement returns an error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC IMPORT OUT= WORK.relabel
          DATAFILE= "&amp;amp;path\Variables and Labels(13NOV2023).xlsx"
          DBMS=EXCEL REPLACE;
     GETNAMES=YES;
	FORMAT Member $15.Num 10. NewNum 10. Variable $40. Type $5. Len 5. Format $20. Informat $20. Label $40. NewLabel $40. Del 1. SortNo1 1.;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=""&gt;37   PROC IMPORT OUT= WORK.relabel
38             DATAFILE= "&amp;amp;path\Variables and Labels(13NOV2023).xlsx"
SYMBOLGEN:  Macro variable PATH resolves to XXX
39             DBMS=EXCEL REPLACE;
40        GETNAMES=YES;
41       FORMAT Member $15.Num 10. NewNum 10. Variable $40. Type $5. Len 5. Format $20. Informat $20. Label $40. NewLabel $40. Del 1. SortNo1 1.;
42   RUN;

WARNING: FORMAT statement is not supported and will be ignored in this procedure. Use PROC DATASETS to modify the data set instead.
SYMBOLGEN:  Macro variable _IMEXSERROR_ resolves to SERROR
NOTE: WORK.RELABEL data set was successfully created.
NOTE: The data set WORK.RELABEL has 3459 observations and 12 variables.
NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.74 seconds
      cpu time            0.29 seconds&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would like to implement specification sheets for database extracts. The database extracts are .sas7bdat files. The excel sheets should help users what columns they want to have visualized in the final excel workbook. Converting the .xlsx files to .csv is not an option in this case (like in:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-XLSX-File-and-Specify-Formats/td-p/914349" target="_blank" rel="noopener"&gt;Solved: PROC IMPORT XLSX File and Specify Formats - SAS Support Communities&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for assistance and best regards&lt;/P&gt;&lt;P&gt;Lukas&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2024 07:21:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/915505#M360743</guid>
      <dc:creator>LuGa</dc:creator>
      <dc:date>2024-02-12T07:21:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to specify formats when importing data from Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/915507#M360745</link>
      <description>&lt;P&gt;I've never seen this syntax from the usage note you reference&amp;nbsp;&lt;A href="https://support.sas.com/kb/15/778.html" target="_blank" rel="noopener"&gt;https://support.sas.com/kb/15/778.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's also a weird note because the table indicates it's a bug without a fix but the code looks like it should be a working solution ....and that for the very old version SAS 9.1.3&lt;/P&gt;
&lt;P&gt;It's clearly not in the documentation:&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acpcref/n0msy4hy1so0ren1acm90iijxn8j.htm" target="_blank" rel="noopener"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acpcref/n0msy4hy1so0ren1acm90iijxn8j.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suggest you use syntax as suggested by the warning text.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;WARNING: FORMAT statement is not supported and will be ignored in this procedure. Use PROC DATASETS to modify the data set instead.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc Datasets changes the descriptor portion of your table in-place. This process will take almost no time and is also independent of the data volume in the table.&lt;/P&gt;
&lt;P&gt;I've made the assumption that the format statement in your code contains key/value pairs of variable name and related format - so some variables are called Format or Label.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that's not the case but you want to define formats, labels etc. for specific variables then the syntax needs to change. It's all documented &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n09nl7f8smat49n1rz1rav5i6a8a.htm" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC IMPORT OUT= WORK.relabel
  DATAFILE= "&amp;amp;path\Variables and Labels(13NOV2023).xlsx"
  DBMS=EXCEL 
  REPLACE;
  GETNAMES=YES;
RUN;

proc datasets lib=work nolist;
  modify relabel;
    FORMAT 
      Member $15.
      Num 10. 
      NewNum 10. 
      Variable $40. 
      Type $5. 
      Len 5. 
      Format $20. 
      Informat $20. 
      Label $40. 
      NewLabel $40. 
      Del 1. 
      SortNo1 1.
      ;
  run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2024 08:05:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/915507#M360745</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-02-12T08:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to specify formats when importing data from Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/915769#M360813</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your reply. Yes it is indeed interesting how inconsistent the documentation of SAS is.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your approach did not help unfortunately.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;ERROR: You are trying to use the numeric format F with the character variable NewNum in data set WORK.RELABEL.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is the error from your suggested&amp;nbsp;&lt;CODE class=""&gt;proc datasets procedure.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As asked in my initial question the excel file should act as a configuration file for non-programmers. That means, that a variable such as Del should be initialized as numeric, no matter what is written in the column.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this possible in SAS?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2024 07:19:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/915769#M360813</guid>
      <dc:creator>LuGa</dc:creator>
      <dc:date>2024-02-13T07:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to specify formats when importing data from Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/915772#M360814</link>
      <description>If you want control over variable types and other attributes, then FORGET the Excel file format and PROC IMPORT. Save the data to a text file and read that with a DATA step.</description>
      <pubDate>Tue, 13 Feb 2024 08:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/915772#M360814</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-13T08:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to specify formats when importing data from Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/915779#M360817</link>
      <description>&lt;P&gt;Dear Kurt,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately this is exactly what I tried to avoid (see my initial post).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BR&lt;BR /&gt;Lukas&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2024 09:30:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/915779#M360817</guid>
      <dc:creator>LuGa</dc:creator>
      <dc:date>2024-02-13T09:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to specify formats when importing data from Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/915782#M360819</link>
      <description>&lt;P&gt;The format-statement assigns formats to the variables written to the dataset, it has no impact on how values are read from a file. So even if the format statement could be used in proc format, it won't fix the problem of types and lengths being guessed by proc import. The only way to avoid such problems is using text files and writing a data step to read the file.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2024 10:15:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/915782#M360819</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2024-02-13T10:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to specify formats when importing data from Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/915783#M360820</link>
      <description>&lt;P&gt;In order to have solid, consistent results which are usable in further automation, text files and DATA steps are the way to go. IMPORT is a stopgap, usable for a quick shot, but not for professional purposes.&lt;/P&gt;
&lt;P&gt;Since all SAS methods to read Excel files are making guesses based on the current contents, the same holds true. Can be used for a quick shot, but not for professional work.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2024 10:40:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/915783#M360820</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-13T10:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to specify formats when importing data from Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/916258#M360929</link>
      <description>&lt;P&gt;Hi Kurt,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for pointing that out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since R (&lt;A href="https://readxl.tidyverse.org/articles/cell-and-column-types.html" target="_blank"&gt;Cell and Column Types • readxl (tidyverse.org)&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;library(readxl)
read_excel("yo.xlsx", col_types = c("date", "skip", "guess", "numeric"))&lt;/PRE&gt;&lt;P&gt;or Python (&lt;A href="https://stackoverflow.com/questions/32591466/python-pandas-how-to-specify-data-types-when-reading-an-excel-file" target="_blank"&gt;Python pandas: how to specify data types when reading an Excel file? - Stack Overflow&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import pandas as pd
df = pd.read_excel('Book1.xlsx',sheetname='Sheet1',header=0,converters={'names':str,'ages':str})&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;are both capable of handling excel data for professional purposes, I will prefer to use those for the required task.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks and BR&lt;/P&gt;&lt;P&gt;Lukas&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2024 05:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/916258#M360929</guid>
      <dc:creator>LuGa</dc:creator>
      <dc:date>2024-02-15T05:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to specify formats when importing data from Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/916259#M360930</link>
      <description>&lt;A href="https://communities.sas.com/t5/SAS-Procedures/PROC-IMPORT-numeric-truncating-problem/m-p/552389" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/PROC-IMPORT-numeric-truncating-problem/m-p/552389&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/excel-engine-dbSAStype-not-importing-variable-correctly/m-p/214359" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/excel-engine-dbSAStype-not-importing-variable-correctly/m-p/214359&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Feb 2024 06:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/916259#M360930</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-02-15T06:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to specify formats when importing data from Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/916260#M360931</link>
      <description>Here is TWO examples:&lt;BR /&gt;&lt;BR /&gt;proc import datafile = "c:\temp\date.xlsx" out =have replace dbms =excel ; &lt;BR /&gt;dbdsopts="dbsastype=(age='numeric' weight='char(20)' weight='char(20)')"; &lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;libname x excel 'c:\temp\date.xlsx';&lt;BR /&gt;data have2;&lt;BR /&gt; set x.'date$'n(dbsastype=(age='numeric' weight='char(20)' weight='char(20)'));&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Feb 2024 06:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-specify-formats-when-importing-data-from-Excel/m-p/916260#M360931</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-02-15T06:09:53Z</dc:date>
    </item>
  </channel>
</rss>

