<?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: Combine multiple Excel files, forcing all variables to character, into a single SAS table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-forcing-all-variables-to-character/m-p/746830#M234325</link>
    <description>In your current methodology you cannot easily do this. You'll have to add in a step to your call execute that ensures that checks if the zip code is numeric and character and correct it - think data step/SQL. There's no way to control the types as you read them in from Excel because Excel doesn't enforce types in the columns.</description>
    <pubDate>Wed, 09 Jun 2021 17:52:53 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-06-09T17:52:53Z</dc:date>
    <item>
      <title>Combine multiple Excel files, forcing all variables to character, into a single SAS table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-forcing-all-variables-to-character/m-p/746827#M234322</link>
      <description>&lt;P&gt;I'm using a macro function to import multiple Excel files and combine them into a single SAS table:&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)));
out="&amp;amp;out";
drop myfiles;

if find(fname, "xlsx", 'it') then 
call execute('
  proc import dbms=xlsx out= _test
            datafile= '||fname||' replace ;
  run;
  proc append data=_test base='||out||' force; run;
  proc delete data=_test; run;
');
run;
filename myfiles clear;

%mend;

%MultImp(dir=G:\MY DRIVE\Folder\test,out=merged);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;I'm running into the following error which results in null values:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WARNING: Variable zip_code not appended because of type mismatch.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I think it is because some files have zip_code stored as text and others have it stored as numeric. How can I update the function to force every column in each spreadsheet to character strings?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jun 2021 17:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-forcing-all-variables-to-character/m-p/746827#M234322</guid>
      <dc:creator>avz</dc:creator>
      <dc:date>2021-06-09T17:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple Excel files, forcing all variables to character, into a single SAS table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-forcing-all-variables-to-character/m-p/746830#M234325</link>
      <description>In your current methodology you cannot easily do this. You'll have to add in a step to your call execute that ensures that checks if the zip code is numeric and character and correct it - think data step/SQL. There's no way to control the types as you read them in from Excel because Excel doesn't enforce types in the columns.</description>
      <pubDate>Wed, 09 Jun 2021 17:52:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-forcing-all-variables-to-character/m-p/746830#M234325</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-09T17:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple Excel files, forcing all variables to character, into a single SAS table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-forcing-all-variables-to-character/m-p/747312#M234532</link>
      <description>&lt;P&gt;I found a related &lt;A href="https://communities.sas.com/t5/SAS-Programming/Convert-all-numeric-variables-to-character/td-p/444205" target="_self"&gt;post&lt;/A&gt;.&amp;nbsp; In it,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;shared a macro that could be applied to a single SAS table and convert all variables to character:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*macro to convert all numeric to char*/%macro vars(dsn);
  %let list=;
  %let type=;
  %let dsid=%sysfunc(open(&amp;amp;dsn));
  %let cnt=%sysfunc(attrn(&amp;amp;dsid,nvars));
   %do i = 1 %to &amp;amp;cnt;
    %let list=&amp;amp;list %sysfunc(varname(&amp;amp;dsid,&amp;amp;i));
    %let type=&amp;amp;type %sysfunc(vartype(&amp;amp;dsid,&amp;amp;i));
   %end;
  %let rc=%sysfunc(close(&amp;amp;dsid));
  data want(drop=
    %do i = 1 %to &amp;amp;cnt;
     %let temp=%scan(&amp;amp;list,&amp;amp;i);
       _&amp;amp;temp
    %end;);
   set &amp;amp;dsn(rename=(
    %do i = 1 %to &amp;amp;cnt;
     %let temp=%scan(&amp;amp;list,&amp;amp;i);
       &amp;amp;temp=_&amp;amp;temp
    %end;));
    %do j = 1 %to &amp;amp;cnt;
     %let temp=%scan(&amp;amp;list,&amp;amp;j);
   /** Change C to N for numeric to character conversion  **/
     %if %scan(&amp;amp;type,&amp;amp;j) = N %then %do;
   /** Also change INPUT to PUT for numeric to character  **/
      &amp;amp;temp=PUT(_&amp;amp;temp,8.);
     %end;
     %else %do;
      &amp;amp;temp=_&amp;amp;temp;
     %end;
    %end;
  run;
%mend vars;
 
%vars(your_dataset_name)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Without success, I've tried to update the original bulk Excel file import function by inserting the %vars macro into the code. I was hoping that the macro will convert the columns in the newly created tables just before it is mended to the base table.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute('
  proc import dbms=xlsx out= _test
            datafile= '||fname||' replace ;
  run;
  %vars(_test);
  proc append data=_test base='||out||' force; run;
  proc delete data=_test; run;
');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you for the assistance.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 11:43:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-forcing-all-variables-to-character/m-p/747312#M234532</guid>
      <dc:creator>avz</dc:creator>
      <dc:date>2021-06-11T11:43:02Z</dc:date>
    </item>
  </channel>
</rss>

