<?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: data truncation while importing and merging excel sheet in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228508#M54299</link>
    <description>It's probably faster to try rather than ask &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Also, if all your files start with datafile AND you don't have any other files that start with datafile you can just use:&lt;BR /&gt;&lt;BR /&gt;data whole;&lt;BR /&gt;format field $950.; length field $950.;&lt;BR /&gt;set datafile:;&lt;BR /&gt;run;</description>
    <pubDate>Mon, 05 Oct 2015 19:38:32 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2015-10-05T19:38:32Z</dc:date>
    <item>
      <title>data truncation while importing and merging excel sheet</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228449#M54283</link>
      <description>&lt;P&gt;I am&amp;nbsp; using following macro to import and combine 40 excel sheet. But some of the fields are getting truncated. Is there a way to avoud truncation in the code below?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options mprint mlogic symbolgen;&lt;BR /&gt;%macro merge(n);*n is the number of your xls files;&lt;BR /&gt;%do i=1 %to &amp;amp;n;&lt;BR /&gt;proc import out=datafile&amp;amp;i datafile="&amp;amp;&amp;amp;file&amp;amp;i" dbms=xls replace;&lt;BR /&gt; sheet="XYZ";&lt;BR /&gt; getnames=yes;&lt;BR /&gt; run;&lt;/P&gt;
&lt;P&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data whole;&lt;BR /&gt; set %do j=1 %to &amp;amp;n;&lt;BR /&gt; datafile&amp;amp;j&lt;BR /&gt; %end;&lt;BR /&gt; ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend merge;&lt;/P&gt;
&lt;P&gt;filename lib pipe 'dir "ABC\*.xls" /b';&lt;BR /&gt;data _null_;&lt;BR /&gt; infile lib;&lt;BR /&gt; input;list;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data file;&lt;BR /&gt; length filenames $ 140;&lt;BR /&gt; infile lib truncover;&lt;BR /&gt; input filenames : $;&lt;BR /&gt; filenames="ABC\"||filenames;&lt;BR /&gt;run;&lt;BR /&gt; &lt;BR /&gt;data null;&lt;BR /&gt; set file;&lt;BR /&gt; call symputx('file'||put(_n_,8. -L ),filenames,'G');&lt;BR /&gt;run;&lt;BR /&gt;options sasautos=work;&lt;BR /&gt;%merge(40) * there are 40 excel sheets that need to imported and combined*&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2015 15:05:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228449#M54283</guid>
      <dc:creator>buckeyefisher</dc:creator>
      <dc:date>2015-10-05T15:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: data truncation while importing and merging excel sheet</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228450#M54284</link>
      <description>&lt;P&gt;You may need to use Options MPRINT to see where this comes up but I suspect you are getting some message in the log about variables having different lengths. The place is most like in the step for DATA whole as the lengths of the variables from the first data set in the set statement are setting the lengths.&lt;/P&gt;
&lt;P&gt;Because you are reading the data with proc import Excel is telling SAS how long the variables are (and what type as well) and likely varies for each data set created by proc import. This is easy to check with Proc Contents on those data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are are going to use proc import you may want to make&amp;nbsp;a dummy data set with no observations with the length and other attributes (format, label) for all of the variables. Then use that as the first data set referenced in the SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or go to a method that reads the data in a more controlled manner such as a data step to read the Excel data saved as CSV.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2015 15:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228450#M54284</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-10-05T15:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: data truncation while importing and merging excel sheet</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228453#M54285</link>
      <description>&lt;P&gt;&lt;FONT color="#FF00FF"&gt;Ballardw,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF00FF"&gt;I tried defining a variable in the output dataset &amp;nbsp;- &amp;nbsp;but still the same problem.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro merge(n);*n is the number of your xls files;&lt;BR /&gt;%do i=1 %to &amp;amp;n;&lt;BR /&gt;proc import out=datafile&amp;amp;i datafile="&amp;amp;&amp;amp;file&amp;amp;i" dbms=xls replace;&lt;BR /&gt; sheet="DrugExport";&lt;BR /&gt; getnames=yes;&lt;BR /&gt; run;&lt;/P&gt;
&lt;P&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;data whole;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;length 'fieldX'n $950;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;set %do j=1 %to &amp;amp;n;&lt;BR /&gt; datafile&amp;amp;j&lt;BR /&gt; %end;&lt;BR /&gt; ;&lt;BR /&gt;*if (prxmatch("m/pfizer/oi",('Originator Company'n)))&amp;gt; 0 or (prxmatch("m/pfizer/oi",('Active Companies'n))) &amp;gt; 0;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%mend merge;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2015 15:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228453#M54285</guid>
      <dc:creator>buckeyefisher</dc:creator>
      <dc:date>2015-10-05T15:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: data truncation while importing and merging excel sheet</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228454#M54286</link>
      <description>Is Excel truncating the field on the import or are you getting truncation after appending the files?</description>
      <pubDate>Mon, 05 Oct 2015 15:52:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228454#M54286</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-10-05T15:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: data truncation while importing and merging excel sheet</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228455#M54287</link>
      <description>&lt;P&gt;Reeza,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My individual import files look fine. Truncation hapend when I merge them.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2015 15:53:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228455#M54287</guid>
      <dc:creator>buckeyefisher</dc:creator>
      <dc:date>2015-10-05T15:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: data truncation while importing and merging excel sheet</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228459#M54288</link>
      <description>Then applying a length and format ahead of the SET should remove the truncation. Verify the format is also set properly otherwise it may appear truncated when the data is actually there.</description>
      <pubDate>Mon, 05 Oct 2015 15:59:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228459#M54288</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-10-05T15:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: data truncation while importing and merging excel sheet</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228484#M54293</link>
      <description>&lt;P&gt;&lt;FONT color="#FF00FF"&gt;Reeza- &amp;nbsp;&lt;/FONT&gt;&lt;FONT color="#FF00FF"&gt;Are suggesting this&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF00FF"&gt;data whole;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;format&amp;nbsp;'fieldX'n &amp;nbsp;$ 950. ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;set %do j=1 %to &amp;amp;n;&lt;BR /&gt;datafile&amp;amp;j&lt;BR /&gt;%end;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2015 18:15:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228484#M54293</guid>
      <dc:creator>buckeyefisher</dc:creator>
      <dc:date>2015-10-05T18:15:06Z</dc:date>
    </item>
    <item>
      <title>Re: data truncation while importing and merging excel sheet</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228504#M54297</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/20840"&gt;@buckeyefisher&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT color="#ff00ff"&gt;Reeza- &amp;nbsp;&lt;/FONT&gt;&lt;FONT color="#ff00ff"&gt;Are suggesting this&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff00ff"&gt;data whole;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#ff00ff"&gt;format&amp;nbsp;'fieldX'n &amp;nbsp;$ 950. ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;set %do j=1 %to &amp;amp;n;&lt;BR /&gt;datafile&amp;amp;j&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Make sure LENGTH AND FORMAT agree.&lt;BR /&gt;data whole;
length 'fieldX'n $ 950 ;
format 'fieldX'n  $ 950. ;

set %do j=1 %to &amp;amp;n;
datafile&amp;amp;j
%end;
&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, 05 Oct 2015 19:30:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228504#M54297</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-10-05T19:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: data truncation while importing and merging excel sheet</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228508#M54299</link>
      <description>It's probably faster to try rather than ask &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Also, if all your files start with datafile AND you don't have any other files that start with datafile you can just use:&lt;BR /&gt;&lt;BR /&gt;data whole;&lt;BR /&gt;format field $950.; length field $950.;&lt;BR /&gt;set datafile:;&lt;BR /&gt;run;</description>
      <pubDate>Mon, 05 Oct 2015 19:38:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/data-truncation-while-importing-and-merging-excel-sheet/m-p/228508#M54299</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-10-05T19:38:32Z</dc:date>
    </item>
  </channel>
</rss>

