<?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: Reading XLSX file and change the all column type into character in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523546#M16217</link>
    <description>&lt;P&gt;If Excel is used to create the file automatically, it can also save to csv automatically. That is a non-issue.&lt;/P&gt;
&lt;P&gt;Excel files are utter **** for production use.&lt;/P&gt;</description>
    <pubDate>Wed, 26 Dec 2018 13:11:22 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-12-26T13:11:22Z</dc:date>
    <item>
      <title>Reading XLSX file and change the all column type into character</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523523#M16210</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi all..&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have an excel file, and i have imported it into dataset in SAS DI&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;(race)&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;..&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But, i got a problem when i exported it and registered the table to&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;another SAS DI (local)&lt;/STRONG&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When i open the dataset in my&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;local&lt;/STRONG&gt;&lt;SPAN&gt;, the column type has changed from character to numeric meanwhile the real type is character in the first&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;SAS DI (race)&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp; and in the excel is general type,&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I dont know why but i'm afraid that one day i'll receive different format (character/numeric) from the excel file because it will generate monthly.&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Then, i decided to make the all column being character format so i think it would be easy for mapping the columns.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My Question :&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;How to change the all of column type to be character when i import the excel file in sas?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd be thankful if you could help me to solve this problem.. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Dec 2018 07:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523523#M16210</guid>
      <dc:creator>wellylly</dc:creator>
      <dc:date>2018-12-26T07:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: Reading XLSX file and change the all column type into character</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523540#M16213</link>
      <description>&lt;P&gt;DO NOT use Excel files for reliable, production-type data transfer. NEVER.&lt;/P&gt;
&lt;P&gt;Save your data to a csv, and read that. The data step will determine all attributes.&lt;/P&gt;
&lt;P&gt;Excel files involve guessing, and attributes depend on the current state of the content; therefore the outcome is never reliably the same.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Dec 2018 12:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523540#M16213</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-26T12:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: Reading XLSX file and change the all column type into character</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523541#M16214</link>
      <description>&lt;P&gt;After importing Excel file, you can use the following code to change Character variable into Numeric variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.class;
run;


proc sql noprint;
select cats(name,'=_',name) into :rename separated by ' '
 from dictionary.columns
  where libname='WORK' and memname='HAVE' and type='num';

select cats(name,'=put(_',name,', best32. -l)') into :change separated by ';'
 from dictionary.columns
  where libname='WORK' and memname='HAVE' and type='num';
quit;

data want;
 set have(rename=(&amp;amp;rename));
 &amp;amp;change;
 drop _:;
 run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Dec 2018 12:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523541#M16214</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-12-26T12:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Reading XLSX file and change the all column type into character</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523543#M16215</link>
      <description>&lt;P&gt;thanks Mr.Kurt for the suggestion. I will receive the excel file every month and it's not possible to me for saving it in csv file because the excel file will generate automatically..&lt;/P&gt;</description>
      <pubDate>Wed, 26 Dec 2018 12:53:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523543#M16215</guid>
      <dc:creator>wellylly</dc:creator>
      <dc:date>2018-12-26T12:53:42Z</dc:date>
    </item>
    <item>
      <title>Re: Reading XLSX file and change the all column type into character</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523544#M16216</link>
      <description>&lt;P&gt;Thanks for the code..&amp;nbsp;&lt;BR /&gt;But if you don't mind, could you show me a code that used to change the all variable type to be character?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Dec 2018 12:59:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523544#M16216</guid>
      <dc:creator>wellylly</dc:creator>
      <dc:date>2018-12-26T12:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: Reading XLSX file and change the all column type into character</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523546#M16217</link>
      <description>&lt;P&gt;If Excel is used to create the file automatically, it can also save to csv automatically. That is a non-issue.&lt;/P&gt;
&lt;P&gt;Excel files are utter **** for production use.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Dec 2018 13:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523546#M16217</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-26T13:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: Reading XLSX file and change the all column type into character</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523550#M16218</link>
      <description>&lt;P&gt;Please explain the process flow in more detail.&amp;nbsp; What it sounds like you did was&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Start with an externally generated Excel file.&lt;/LI&gt;
&lt;LI&gt;Import that into SAS using SAS/DI&lt;/LI&gt;
&lt;LI&gt;Export a NEW Excel file from SAS/DI&lt;/LI&gt;
&lt;LI&gt;Import this second Excel file into a different instance of SAS/DI.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;If you are trying to move the exact same data then why not send the original file.&lt;/P&gt;
&lt;P&gt;If you are trying to send modified data then why not send a SAS dataset instead of an Excel file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or perhaps the problem actually is that the first step is inconsistently generating the column types when processing different versions of the source Excel file and the second instance of SAS has nothing to do with the core issue. Instead the issue is quality control in the system that is generating the source Excel files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not sure if SAS/DI has any tools to let your coerce Excel files that do not themselves enforce a standard structure into a standard structured SAS dataset.&amp;nbsp; It is possible in SAS to program code to compare the structure of a dataset (for example the one you got be importing the Excel file) to a standard and when possible convert numbers to character and vice versa.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that Excel is NOT a database, it is a spreadsheet.&amp;nbsp; If you want Excel to treat a variable as character then DO NOT set the format to GENERAL, set the format to TEXT.&amp;nbsp; In general format Excel will look at the characters you enter and guess what you mean.&amp;nbsp; So it will convert an ID string that happens to be all digits to a number and in doing it will lose any leading zero characters.&amp;nbsp; It might also convert a string with just digits and hyphens into DATE values.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Dec 2018 14:36:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523550#M16218</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-26T14:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: Reading XLSX file and change the all column type into character</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523615#M16220</link>
      <description>&lt;P&gt;Many thanks to answer my question..&lt;BR /&gt;&lt;BR /&gt;Let me explain what i did:&lt;BR /&gt;1. I have an excel file with multiple sheets.&lt;BR /&gt;2. I used &lt;STRONG&gt;user wiritten&lt;/STRONG&gt; to generate the excel file in DI using the code.&lt;/P&gt;&lt;P&gt;an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;proc import datafile="/home/coba.xlsx"&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;out=TRS.eir&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;dbms=xlsx replace;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;sheet="Outstanding EIR"; &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;getnames=yes;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, the datasets are created.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;3. I made a library then I registered the tables (datasets) into the library.&lt;BR /&gt;4. I made a job for mapping the datasets using Data Validation, so that I could get Portfolio Dataset.&lt;BR /&gt;5. But the problem is i can't make sure if my client sets the variables types (&lt;STRONG&gt;excel&lt;/STRONG&gt;) as general, so sometimes it may be different every month (numeric or character), the type doesn't fix. Then, my partner suggested me to change the all variables types to character (the same way i did to txt file in DI), so it would be easy for me to map the columns without afraid if the data type has changed next month.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;My question is : How to change the all variables types to character&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;(before i map the columns)?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;NB&lt;/STRONG&gt;: Another experiment I've tried to change the variables types one by one to be character by added external file without the code, just import by choosing the dataset (from the sama excel file) in library before as reference table then I got the result like this picture below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="coba enkrip.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25891i7827FA1A38F05027/image-size/large?v=v2&amp;amp;px=999" role="button" title="coba enkrip.png" alt="coba enkrip.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I have no idea to change the all variable types to character.&lt;/STRONG&gt;. &lt;STRONG&gt;Is it possible or not&lt;/STRONG&gt;? &lt;STRONG&gt;Or maybe you have another suggestion??&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;Thanks before..&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 07:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523615#M16220</guid>
      <dc:creator>wellylly</dc:creator>
      <dc:date>2018-12-27T07:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Reading XLSX file and change the all column type into character</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523630#M16221</link>
      <description>&lt;P&gt;There is not any way that I know of to tell PROC IMPORT to treat all (or any specific) column as text.&amp;nbsp; It will makes its best guess based on what it sees in the column in the spreadsheet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can give the users a template they will use to populate the data then you might be able to force PROC IMPORT to treat the columns as text by including a first line of data that has characters in every column.&amp;nbsp; So the first two lines in your spreadsheet might look like:&lt;/P&gt;
&lt;PRE&gt;VAR1|VAR2|VAR3
XXXX|XXXX|XXXX&lt;/PRE&gt;
&lt;P&gt;And then just tell the users to enter their data starting in the third row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If all of your column headers are already text then perhaps you could use the GETNAMES=NO statement on PROC IMPORT to get the same effect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try changing your program to something like this that will read it without names and then use the first row to rename the columns.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import
  datafile="/home/coba.xlsx" dbms=xlsx 
  out=nonames replace 
;
  sheet="Outstanding EIR"; 
  getnames=NO;
run;
proc transpose data=nonames(obs=1) out=names ;
  var _all_;
run;
data _null_;
  length rename $32767;
  do until (eof);
    set names end=eof;
    rename=catx(' ',rename,catx('=',_name_,nliteral(col1)));
  end;
  call symputx('rename',rename);
run;
data TRS.eir ;
  set nonames (firstobs=2);
  rename &amp;amp;rename ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the column headers are messy so that they do not automatically make good variable names you might want to use this more complex method below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import
  datafile="/home/coba.xlsx" dbms=xlsx 
  out=nonames replace 
;
  sheet="Outstanding EIR"; 
  getnames=NO;
run;

proc import
  datafile="/home/coba.xlsx" dbms=xlsx 
  out=names replace 
;
  sheet="Outstanding EIR"; 
  getnames=YES;
run;

proc transpose data=nonames(obs=0) out=bad_names name=from;
  var _all_;
run;
proc transpose data=names(obs=0) out=good_names name=to;
  var _all_;
run;
data _null_;
  length rename $32767;
  do until (eof);
     merge bad_names good_names end=eof;
     rename=catx(' ',rename,catx('=',from,to));
  end;
  call symputx('rename',rename);
run;
data TRS.eir ;
  set nonames (firstobs=2);
  rename &amp;amp;rename ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 13:58:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523630#M16221</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-27T13:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: Reading XLSX file and change the all column type into character</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523811#M16222</link>
      <description>&lt;P&gt;&lt;FONT face="verdana,geneva"&gt;You can try using the DBSASTYPE data set option with the EXCEL or PCFILES LIBNAME engine:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname xl excel 'C:\temp\Class.xlsx';

data work.class;
set xl.class(dbsastype=(age='char(10)' height='char(10)' weight='char(10)' ));
run;

libname xl pcfiles path='C:\temp\Class.xlsx';

data work.class;
set xl.class(dbsastype=(age='char(10)' height='char(10)' weight='char(10)' ));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva"&gt;Vince DelGobbo&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva"&gt;SAS R&amp;amp;D&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Dec 2018 02:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Reading-XLSX-file-and-change-the-all-column-type-into-character/m-p/523811#M16222</guid>
      <dc:creator>Vince_SAS</dc:creator>
      <dc:date>2018-12-29T02:47:30Z</dc:date>
    </item>
  </channel>
</rss>

