<?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: Truncation of variable when importing excel (.xlsx) file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779940#M248452</link>
    <description>&lt;P&gt;Hey Maguiremq&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately the guessingrows option does not work. I have already tried it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first variable does not have a variable name and is just named "VAR1" when imported. This might cause an issue?&lt;/P&gt;</description>
    <pubDate>Fri, 12 Nov 2021 09:33:19 GMT</pubDate>
    <dc:creator>mgrasmussen</dc:creator>
    <dc:date>2021-11-12T09:33:19Z</dc:date>
    <item>
      <title>Truncation of variable when importing excel (.xlsx) file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779800#M248414</link>
      <description>&lt;P&gt;Dear SAS experts&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to import a dataset using the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc important datafile="Datafilepath"&lt;/P&gt;
&lt;P&gt;dbms=xlsx replace&lt;/P&gt;
&lt;P&gt;out=newdatasetname;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first variable - A - contains letters and the row with the most characters (including spaces) contains 32 characters. When I import the excel file using the command above it appears that the variable is truncated at 17 characters (length: 17, /format/informat: $17) .&lt;/P&gt;
&lt;P&gt;I was inspired from reading post online to try to include a length command, a format command and a guessrows option (one at a time) in the proc import to change this but thus far with no success. I included these above the run statement.&lt;/P&gt;
&lt;P&gt;This variable (A) is the only character variable in the dataset and is placed as the first variable in the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help me understand this issue? Am I on the right track by including a format, length or guessrows command?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Nov 2021 14:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779800#M248414</guid>
      <dc:creator>mgrasmussen</dc:creator>
      <dc:date>2021-11-11T14:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of variable when importing excel (.xlsx) file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779807#M248417</link>
      <description>&lt;P&gt;I would consider using the GUESSINGROWS = option in PROC IMPORT. I think that it is trying to guess the length of the column based on the first twenty observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile = "your-data-file"
out = want
dbms = xlsx
replace;
guessingrows = 1000; /* or 50 or 100 or 5000 or MAX - depends on size and time constraints. */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also trying using the LIBNAME statement with the XLSX engine. That may be better -- not quite sure without seeing the data. I personally loathe when data is sent to me in excel, and I would use the LIBNAME statement with the XLSX engine if data is sent to me in this form.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname path2xl xlsx "your-excel-file-here";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sgf/2020/03/10/accessing-excel-files-using-libname-xlsx/" target="_self"&gt;LIBNAME XLSX post&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p13kvtl8ezj13in17i6m99jypcwi.htm" target="_self"&gt;GUESSINGROWS statement&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Nov 2021 14:49:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779807#M248417</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-11-11T14:49:30Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of variable when importing excel (.xlsx) file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779877#M248440</link>
      <description>&lt;P&gt;The most likely cause of this problem is that your longer columns are not in the first few rows of your spreadsheet and the Excel engine SAS uses to import the data only checks the first few rows of data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A quick fix is to add a dummy first row of data to your spreadsheet and ensure column A has 32 characters in it. Read that into SAS&amp;nbsp; and delete this row.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;GUESSINGROWS is not a valid option for DBMS = XLSX.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 00:44:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779877#M248440</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-11-12T00:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of variable when importing excel (.xlsx) file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779888#M248443</link>
      <description>Unfortunately most of the standard suggestions (length/informat/guessingrows) don't apply when importing Excel files. If you can, save it as CSV and importing that will allow you way more control. Obviously this is easy and straightforward if its a one time process but a pain if it's required to be an automation of some sort.</description>
      <pubDate>Fri, 12 Nov 2021 01:26:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779888#M248443</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-11-12T01:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of variable when importing excel (.xlsx) file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779909#M248446</link>
      <description>&lt;P&gt;I would be very surprised if SAS truncated a character string from an XLSX file.&amp;nbsp; You could try using the XLSX libref engine instead of PROC IMPORT and see if that helps.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname in xlsx "Datafilepath";
proc copy inlib=in outlib=work;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise try making a small file that replicates the issue and posting it here.&lt;/P&gt;
&lt;P&gt;Or better open a support ticket with SAS support and let them figure it out.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 03:00:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779909#M248446</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-12T03:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of variable when importing excel (.xlsx) file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779930#M248448</link>
      <description>&lt;P&gt;If you want control over how the data is imported, save as csv from Excel and read that with a data step.&lt;/P&gt;
&lt;P&gt;Do not use Excel files, do not use PROC IMPORT.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 06:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779930#M248448</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-12T06:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of variable when importing excel (.xlsx) file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779940#M248452</link>
      <description>&lt;P&gt;Hey Maguiremq&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately the guessingrows option does not work. I have already tried it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first variable does not have a variable name and is just named "VAR1" when imported. This might cause an issue?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 09:33:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779940#M248452</guid>
      <dc:creator>mgrasmussen</dc:creator>
      <dc:date>2021-11-12T09:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of variable when importing excel (.xlsx) file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779941#M248453</link>
      <description>&lt;P&gt;Hey SASKIWI&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are right. If the first column in the first row there are only few letters. There are more characters in the rows lower in the first column.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 09:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779941#M248453</guid>
      <dc:creator>mgrasmussen</dc:creator>
      <dc:date>2021-11-12T09:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of variable when importing excel (.xlsx) file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779942#M248454</link>
      <description>&lt;P&gt;Hey Reeza&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have changed it now so I do not import an excel file but a .csv using proc import. But there is still some truncation (at 19 characters now instead of 17, for some reason).&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 09:38:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779942#M248454</guid>
      <dc:creator>mgrasmussen</dc:creator>
      <dc:date>2021-11-12T09:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of variable when importing excel (.xlsx) file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779943#M248455</link>
      <description>&lt;P&gt;Hey Kurt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But using a data step and the infile statement requires that I know the names of all variables that I am importing, correct? Or can I simply tell SAS to make the most appropriate formatting? I am asking this based on the example some 3/4s down on this site:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://sasexamplecode.com/3-ways-to-import-a-csv-file-into-sas-examples/" target="_blank"&gt;https://sasexamplecode.com/3-ways-to-import-a-csv-file-into-sas-examples/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 09:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779943#M248455</guid>
      <dc:creator>mgrasmussen</dc:creator>
      <dc:date>2021-11-12T09:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of variable when importing excel (.xlsx) file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779948#M248460</link>
      <description>&lt;P&gt;Dear all&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281770"&gt;@maguiremq&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;It seems that issue is that I am doing all of this within a macro. I tried importing it as an .csv file instead and added the guessingrow option outside a macro and it works as intended. The same code does not work within a macro. The files are the same, but when created within a macro there is this truncation.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 10:28:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779948#M248460</guid>
      <dc:creator>mgrasmussen</dc:creator>
      <dc:date>2021-11-12T10:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of variable when importing excel (.xlsx) file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779970#M248466</link>
      <description>&lt;P&gt;Macro's just generate SAS code for SAS to run.&amp;nbsp; If you are running the same code it does not matter whether you hard-coded the text of the program or let a macro generate the code for you.&amp;nbsp; Turn on the MPRINT option to see what SAS code the macro is actually generating.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 13:45:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779970#M248466</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-12T13:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of variable when importing excel (.xlsx) file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779972#M248467</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/388382"&gt;@mgrasmussen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hey Kurt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But using a data step and the infile statement requires that I know the names of all variables that I am importing, correct? Or can I simply tell SAS to make the most appropriate formatting? I am asking this based on the example some 3/4s down on this site:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://sasexamplecode.com/3-ways-to-import-a-csv-file-into-sas-examples/" target="_blank" rel="noopener"&gt;https://sasexamplecode.com/3-ways-to-import-a-csv-file-into-sas-examples/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That description of how to write a data step is a little messed up.&amp;nbsp; If users have been following that advice maybe that is why I see such convoluted confused data steps posted on this forum.&amp;nbsp; &amp;nbsp;Two key things:&lt;/P&gt;
&lt;P&gt;1) You should DEFINE the variables first using a LENGTH statement (or LENGTH= option on ATTRIB statement).&amp;nbsp; INFORMAT and FORMAT are rarely needed. SAS knows how to read and write normal numbers and text.&amp;nbsp; Don't force SAS to guess how you want the variables defined by how the variable is first used in other statements like INFORMAT, FORMAT or INPUT in the data step.&amp;nbsp; It can work, but you really need to understand the rules SAS uses to guess the type and length of the variable to be sure the variable is defined as you intended, so not the advice to be giving novices.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2)&amp;nbsp; You can use the older MISSOVER option on the INFILE statement, but make sure you don't slip into using formatted input instead of list mode input or it might cause text at the end of the line to be ignored.&amp;nbsp; The TRUNCOVER option is safer, especially for novices.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want a better tool for guessing how to read a delimited text file try this macro:&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/csv2ds.sas" target="_blank" rel="noopener"&gt;https://github.com/sasutils/macros/blob/master/csv2ds.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 14:00:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Truncation-of-variable-when-importing-excel-xlsx-file/m-p/779972#M248467</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-12T14:00:29Z</dc:date>
    </item>
  </channel>
</rss>

