<?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: Importing an xlsx file, preserving all characters as text as they appear in Excel in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928896#M365490</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile='c:\temp\temp.xlsx' out=class dbms=excel replace;
sheet='xxxx';
dbdsopts="dbsastype=(age='char(20)' weight='char(20)' height='char(20)')";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can specify this kind of variable to be character type as well with EXCEL engine.&lt;/P&gt;</description>
    <pubDate>Sat, 18 May 2024 05:51:28 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-05-18T05:51:28Z</dc:date>
    <item>
      <title>Importing an xlsx file, preserving all characters as text as they appear in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928868#M365476</link>
      <description>&lt;P&gt;Hi folks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am attempting to read an xlsx file into SAS without SAS doing anything to modify the the variable types or the characters as they appear when viewing the xlsx file in Excel. In other words, if something looks like a date, regardless of how it's stored in the xlsx file (e.g., "11/25/2023"), it'll show up in sas as a character variable as that same value (e.g., "11/25/2023"). In other words, I'd like to replicate what the Import Data wizard in SAS does when it just defines all fields as character, as in the following attributes for one particular column, for example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;type=String&lt;/P&gt;
&lt;P&gt;Source Informat=$CHAR29&lt;/P&gt;
&lt;P&gt;Len.=29&lt;/P&gt;
&lt;P&gt;Output Format=$CHAR29.&lt;/P&gt;
&lt;P&gt;Output Informat=$CHAR29.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code automatically generated from the Import Data wizard when I do this contains the DATALINES4 statement, which I can't use because I can't just fill all of these in, as I'm trying to load the data in without having to look at the contents. I'd be fine, though, if I can define the variable types/lengths/formats/etc., as I know what the variables are and what they'll be named.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I do this without having to fill in the DATALINES4 content?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to be able to specify the sheet within the Excel workbook in question as well.&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 19:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928868#M365476</guid>
      <dc:creator>robeldritch</dc:creator>
      <dc:date>2024-05-17T19:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an xlsx file, preserving all characters as text as they appear in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928874#M365477</link>
      <description>&lt;P&gt;Proc Import file="&amp;lt;path&amp;gt;\your excel file.xlsx" out=yourdatasetname&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dbms=Excel replace;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mixed=yes;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe.&lt;/P&gt;
&lt;P&gt;The documentation states (emphasis added):&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-eDocBody"&gt;
&lt;DIV id="n0msy4hy1so0ren1acm90iijxn8j" class="xis-topic"&gt;
&lt;DIV id="n010vbd2e5jyg5n1rvfey0a1lyo0" class="xis-subTopic"&gt;
&lt;DIV id="n0bh60l5spojxzn11t7vvq0d55ka" class="xis-subSubTopic"&gt;
&lt;DIV id="p12kprm93bu1lbn1grc3sv4ss8a9" class="xis-topicContent"&gt;
&lt;DIV id="p1sfsnohmklsn7n1v5fqxb246qk6" class="xis-argDescriptionPair"&gt;
&lt;H4 class="xis-argument"&gt;MIXED=YES | NO&lt;/H4&gt;
&lt;DIV class="xis-argumentDescription"&gt;
&lt;P class="xis-paraSimpleFirst"&gt;assigns a SAS character type for the column and converts all numeric data values to character data values when mixed data types are found.&lt;/P&gt;
&lt;DIV id="p0i7uhrmwd22ymn1jrw6cwb6a17u" class="xis-paraSimple"&gt;YES specifies that the connection is set to import mode and updates are not allowed. The XLSX and XLS formats assume MIXED=YES.&lt;/DIV&gt;
&lt;DIV id="n1mc4uakxuqmzdn1bpiysagmm9ps" class="xis-note"&gt;&lt;STRONG&gt;&lt;SPAN class="xis-noteGenText"&gt;Note: &lt;/SPAN&gt;Due to how the Microsoft ACE driver and the Microsoft Jet Excel driver work, using MIXED=YES could result in improper text variable lengths.&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV id="p15m7ofnbol0vcn16lt1zo92hgy1" class="xis-paraSimple"&gt;NO assigns numeric or character type for the column, depending on the majority of the type data that is found.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 19:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928874#M365477</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-17T19:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an xlsx file, preserving all characters as text as they appear in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928875#M365478</link>
      <description>&lt;P&gt;The import wizard uses two stages: first, it converts the Excel spreadsheet to text on the client side, and then makes this text part of the code.&lt;/P&gt;
&lt;P&gt;If you want full control of the import, you must save the data to a text (csv) file, upload it if you use SAS on a server, and then read the file with a DATA step.&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 19:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928875#M365478</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-05-17T19:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an xlsx file, preserving all characters as text as they appear in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928889#M365484</link>
      <description>&lt;P&gt;Hi ballardw--thanks for the response. Unfortunately, this didn't end up working for me, as it still brought in some fields as numbers (namely, the date fields I described in my original post, which of course were read in as number of days since whatever date, as well as other fields). That said, I found a really roundabout solution that I'll post below...&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2024 03:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928889#M365484</guid>
      <dc:creator>robeldritch</dc:creator>
      <dc:date>2024-05-18T03:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an xlsx file, preserving all characters as text as they appear in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928890#M365485</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your response. Unfortunately, saving each file as a .csv, as much as I'd like to, isn't doable in this situation--the client will be receiving these .xlsx (and some are .xlsm) files (expected to be well over 100) at some point in the near future and won't have time to save all of them as such. I'm not aware of a way to save all the files as a .csv en masse. I tried something in SAS to that effect, but all it ended up doing was saving them with a .csv file extension but where the underlying data were still .xlsx, and this move somehow corrupted them such that they weren't openable even from the file explorer, much less in SAS. I could import them into SAS en masse with the intention of exporting as a .csv, but then I run into the problem that brought me here in the first place.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, I found a really roundabout solution, which I'll post below...&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2024 03:29:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928890#M365485</guid>
      <dc:creator>robeldritch</dc:creator>
      <dc:date>2024-05-18T03:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an xlsx file, preserving all characters as text as they appear in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928891#M365486</link>
      <description>&lt;P&gt;Ok, so here's the really roundabout solution involving DDE (yup...) I came up with, appropriating some things from a few different resources, including some old SAS Communities threads (I apologize for not citing/tagging the folks who have unbeknownst to them contributed to this ridiculous block of code):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro a; %do i=1 %to &amp;amp;n;
	options noxwait noxsync;
	%SYSEXEC "H:\misc\equip\data\core_&amp;amp;i..xlsx";

	%let ws=ReOp6-Equip Depr;
		%let r1=1;
		%let c1=1;
	  	%let r2=10000;
	  	%let c2=24;

	  	FileName xl
	    	DDE
	      	"Excel|&amp;amp;ws!r&amp;amp;r1.c&amp;amp;c1.:r&amp;amp;r2.c&amp;amp;c2."
	       	LRecL=5000
	       	NoTab;

	data _null_;  
		length fid rc start stop time 8;  
		fid=fopen('xl');  
		if (fid le 0) then do;    
			start=datetime();    
			stop=start+20;    
			do while (fid le 0);      
				fid=fopen('xl');      
				time=datetime();      
				if (time ge stop) then fid=1;      
				end;    
			end;  
		rc=fclose(fid); 
	run;

	data core_&amp;amp;i.b;
		Infile XL
		DSD
		Pad
		DLM = "09"x;

	    length Col1-Col%eval(&amp;amp;c2.-&amp;amp;c1.-1) $300;
	    format Col1-Col%eval(&amp;amp;c2.-&amp;amp;c1.-1) $300.;
	    input Col1-Col%eval(&amp;amp;c2.-&amp;amp;c1.-1 );
	run ;

	filename cmds dde 'excel|system';
	data _null_;
	  file cmds;
	  put '[close("H:\misc\equip\data\core_&amp;amp;i..xlsx")]';
	  put '[quit]';
	run;
%end; %mend a; %a&lt;BR /&gt;&lt;BR /&gt;/*THIS THEN REPEATS FOR THE .xlsm WORKBOOKS...*/&lt;/PRE&gt;
&lt;P&gt;It sure ain't very elegant or efficient, but it's the only thing I've tried so far that has actually worked for my purposes, so I'm not messing with it for now.&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2024 03:37:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928891#M365486</guid>
      <dc:creator>robeldritch</dc:creator>
      <dc:date>2024-05-18T03:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an xlsx file, preserving all characters as text as they appear in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928896#M365490</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile='c:\temp\temp.xlsx' out=class dbms=excel replace;
sheet='xxxx';
dbdsopts="dbsastype=(age='char(20)' weight='char(20)' height='char(20)')";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can specify this kind of variable to be character type as well with EXCEL engine.&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2024 05:51:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928896#M365490</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-05-18T05:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an xlsx file, preserving all characters as text as they appear in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928899#M365492</link>
      <description>&lt;P&gt;Hi Ksharp,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for this--I had tried this solution already, and it's not giving me what I want. For example, even though it's bringing the date column in as a character variable, it's still just in the form of days since such and such date but as a string instead of a numerical variable.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2024 06:43:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928899#M365492</guid>
      <dc:creator>robeldritch</dc:creator>
      <dc:date>2024-05-18T06:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an xlsx file, preserving all characters as text as they appear in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928917#M365501</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183156"&gt;@robeldritch&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Ksharp,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for this--I had tried this solution already, and it's not giving me what I want. For example, even though it's bringing the date column in as a character variable, it's still just in the form of days since such and such date but as a string instead of a numerical variable.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is the behavior that is causing the issue for you.&amp;nbsp; When SAS decides that a date (or datetime they are really the same in Excel since time of day is just stored as a fraction of day) value needs to be converted into a character variable it does not apply the Excel formatting to it.&amp;nbsp; Instead it just converts the underlying number (the value that is actually stored in the cell) into a character string.&amp;nbsp; The same thing happens with other EXCEL display formats.&amp;nbsp; For example currency displays.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take this sheet:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1716055315063.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96625i375B53BABD99A431/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1716055315063.png" alt="Tom_0-1716055315063.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If I use PROC IMPORT to read that then because the last row has character strings in every column all three variables will be character.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_1-1716055370973.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96626iE8EDA3A20DE60E04/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_1-1716055370973.png" alt="Tom_1-1716055370973.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your example of using DDE is one way to have SAS control EXCEL to do what you want.&amp;nbsp; But DDE is a deprecated technology and can by hijacked by random other processes on your PC making it not a reliable choice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But for DDE to work you have to be running EXCEL locally anyway so you could instead use Visual Basic or Powershell commands instead to convert the sheets in the XLSX workbooks into CSV (or other text) files that could then be read by SAS as all character variables very easily.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2024 18:05:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928917#M365501</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-05-18T18:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an xlsx file, preserving all characters as text as they appear in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928921#M365504</link>
      <description>&lt;P&gt;If you know what display format you want applied to the values then just add a step to do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example if your generated dataset is named FROM_EXCEL and the variable created from the column in the spreadsheet with the DATE values is named DATE you might want to run something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set from_excel;
  if not missing(input(date,??32.)) then date=put(input(date,32.)+'30dec1899'd,mmddyy10.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 18 May 2024 18:25:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928921#M365504</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-05-18T18:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an xlsx file, preserving all characters as text as they appear in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928922#M365505</link>
      <description>Hi Tom, &lt;BR /&gt;&lt;BR /&gt;I wish I knew what date format I wanted! The issue is that I don't, and the sheets I'm reading in are all manner of formats, including erroneous ones (e.g., 23/17/24). The client just wants everything preserved exactly as it's displayed on the Excel sheet (I realize the underlying data may look different). I'd be curious to see how this might be done with the other tools you mentioned above (power shell, etc). I realize DDE isn't ideal for the reasons you described, but it was the only solution that worked for me so far. Thanks for your input!</description>
      <pubDate>Sat, 18 May 2024 18:52:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928922#M365505</guid>
      <dc:creator>robeldritch</dc:creator>
      <dc:date>2024-05-18T18:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an xlsx file, preserving all characters as text as they appear in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928924#M365507</link>
      <description>&lt;P&gt;Qucik google search found this StackOverflow question that has a visual basic script for converting all worksheets in all XLSX files in a folder into text files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/17141885/batch-convert-excel-to-text-delimited-files" target="_blank"&gt;https://stackoverflow.com/questions/17141885/batch-convert-excel-to-text-delimited-files&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2024 19:09:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928924#M365507</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-05-18T19:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an xlsx file, preserving all characters as text as they appear in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928936#M365514</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183156"&gt;@robeldritch&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Ok, so here's the really roundabout solution involving DDE (yup...) I came up with, appropriating some things from a few different resources, including some old SAS Communities threads (I apologize for not citing/tagging the folks who have unbeknownst to them contributed to this ridiculous block of code):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;IF you put this into a production process you will need to be aware that DDE is no longer supported and that the internal communications channels used by DDE may be preempted by other programs. I had one program that used DDE to "get around" opening files. Until it didn't work. Because our organization started using Cisco Jabber.&lt;/P&gt;
&lt;P&gt;The processes on the system running SAS had to have Jabber KILLED, not just turned off, to allow DDE to work. That was 7 years ago. I cannot believe that there are fewer programs that will interfere with DDE now.&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>Sun, 19 May 2024 04:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928936#M365514</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-19T04:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an xlsx file, preserving all characters as text as they appear in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928938#M365516</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183156"&gt;@robeldritch&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on your answers it appears you're dealing with somewhat conflicting requirements and expectations. It might be worth for you to have a discussion with your customer and explain some of the differences between an Excel spreadsheet and a (SAS) table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You simply can't have source date strings that don't represent a valid date and then expect to store this as a SAS data value (that just MUST be a valid date). You also can't apply formats "cell based" like in Excel.&lt;/P&gt;
&lt;P&gt;The only way I can think of to get strings in a SAS table as seen in an Excel spreadsheet is to save the Excel sheets as csv using the Excel save as... function and then use SAS to read these csv files into SAS character variables (and only character variables).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;already shared a link with you for a vbs script that does such conversion to csv files. I've also made a test with a chatGPT generated script which worked quite well from start (Microsoft knows Microsoft...).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to take above avenue then for automation first questions are:&lt;/P&gt;
&lt;P&gt;- Do you have option XCMD set?&lt;/P&gt;
&lt;P&gt;- Can you confirm that your SAS environment executes under Windows.&lt;/P&gt;</description>
      <pubDate>Sun, 19 May 2024 06:35:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928938#M365516</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-19T06:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an xlsx file, preserving all characters as text as they appear in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928949#M365524</link>
      <description>&lt;P&gt;If there are such programs that conflict with the DDE's requirements for establishing/maintaining a connection in our organization, they're not conflicting here. The only thing I'm doing (temporarily) to ensure the connection is established and maintained (until I close it) is to relax the protected view Trust settings when generating copies of the files in the folder (also done in SAS). This is just a one-time thing--I just want to be able to have it work this one time and as simply as possible (i.e., the less applications involved, the better). I'm appending specific row/column ranges from each sheet to a master table and inserting a column in each one with another value from elsewhere on each sheet as an identifier before appending--all of which I know how to do easily in SAS. So if I can do all the steps with one script in SAS, then that's more ideal for my situation.&lt;/P&gt;</description>
      <pubDate>Sun, 19 May 2024 14:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928949#M365524</guid>
      <dc:creator>robeldritch</dc:creator>
      <dc:date>2024-05-19T14:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an xlsx file, preserving all characters as text as they appear in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928950#M365525</link>
      <description>&lt;P&gt;Thanks for the reply, Patrick. If I had more time, I would implement a solution with one of those other applications. Since I'm most familiar with SAS, if I can get it all done (by "it", I mean all of the data transformation and appending this project requires after reading in the files, aside from reading in the files themselves) with just clicking the "Run" button in a single instance of SAS, which is what I've got now, then that's what I'm going with. I appreciate the other solutions y'all have presented in this thread using those other applications (VBS, Powershell, ChatGPT), and I'll certainly look to those for future projects involving this kind of purpose. I'm just not familiar with those, and for me to get as familiar with, for example, VBS, as I would need to get in order to make that script work (to be clear, I've never worked with VBS programming before) would take more time than I have to devote to this project at the moment.&lt;/P&gt;</description>
      <pubDate>Sun, 19 May 2024 15:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928950#M365525</guid>
      <dc:creator>robeldritch</dc:creator>
      <dc:date>2024-05-19T15:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an xlsx file, preserving all characters as text as they appear in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928981#M365545</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183156"&gt;@robeldritch&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've heard this "no time" argument already way too often. I agree that not everything needs to be "perfect" but I also believe you need to always ask yourself what level of robustness you need.&lt;/P&gt;
&lt;P&gt;For an adhoc job your DDE would be good enough for me but when it comes to production jobs that run regularly then spending the time upfront is imho a must. If you don't then it's only a question of time until something falls over and then it's a production issue with all the visibility, loss of customer trust and loss of your reputation. ...plus investigation and fixing things will likely add much more time than trying to "get it right" from start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also be aware that besides of everything else that already has been said DDE is really slow.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Creating and calling a .vbs for conversion of Excel to csv isn't hard. With the right prompts chatGPT provided me with code that I could use almost "as is". It's even given me the syntax how to call the .vbs with parameter passing. The vbs is basically automation of Excel "Save As... csv".&lt;/P&gt;
&lt;PRE&gt;sheet.SaveAs targetPath, 6     REM 6 refers to the CSV format&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure if it's still worth it but because I've got something working here the code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/** sample call **/
/* 1. create driver table with source paths to excel and libref for target tables */
%let source_dir=C:\temp\xlsx2csv;
%let target_lib=WORK;
data ExcelsToRead;
  infile %tslit(dir /B "&amp;amp;source_dir\*.xls*") pipe truncover end=last;
  input ExcelWorkbook $100.;
  if upcase(scan(ExcelWorkbook,-1,'.')) in ('XLSX','XLSM');
  target_lib="&amp;amp;target_lib";
run;
  
/* 2. call macro once per source Excel */
filename codegen temp;
data _null_;
  file codegen;
/*  file print;*/
  set ExcelsToRead;
  length cmd $300;
  cmd=cats('%convertExcelwb2SAStbl(source_file=%nrstr(',"&amp;amp;source_dir\",ExcelWorkbook,')');
  cmd=cats(cmd,',outlib=',target_lib,');');
  put cmd;
run;

%include codegen /source2;
filename codegen clear;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And here the macro that gets called and does all the work:&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro convertExcelwb2SAStbl(
  /* required parameters */
  source_file=
  /* optional parameters */
  ,outlib=WORK
  ,csv_folder=       /* WARNING! All .csv files under this folder will get deleted. Default points to folder under WORK. */
  ,vbscript=
  ,vbscript_gen=yes
  ,delObsAllMissing=no
  );

  %local work_path;
  %let work_path=%sysfunc(pathname(work));

  %if %nrbquote(&amp;amp;csv_folder) = %nrbquote() %then %let csv_folder=&amp;amp;work_path\csv_folder;
  %if %nrbquote(&amp;amp;vbscript)   = %nrbquote() %then %let vbscript  =&amp;amp;work_path\excel2csv.vbs;

  /** create vb script for conversion of Excel workbook to csv files (save as... csv) **/
  %global vbscript_gen_flg;
  %if %upcase(&amp;amp;vbscript_gen)=YES and %nrbquote(&amp;amp;vbscript_gen_flg) ne %nrbquote(1) %then
    %do;
      %macro gen_vbs(
        outpath=&amp;amp;vbscript
        );
        data _null_;
        /*  file print;*/
          file "&amp;amp;outpath";
          put
            'REM Usage:' /
            'REM cscript "C:\path\to\vbs\ConvertXlsxToCsv.vbs" "C:\path\to\source.xlsx" "C:\path\to\target\folder"' /

            'REM Get the arguments' /
            'Dim args' /
            'Set args = WScript.Arguments' /

            'If args.Count &amp;lt;&amp;gt; 2 Then' /
            '    WScript.Echo "Usage: cscript ConvertXlsxToCsv.vbs &amp;lt;source path&amp;gt; &amp;lt;target folder&amp;gt;"' /
            '    WScript.Quit 1' /
            'End If' /

            'Dim sourcePath, targetFolder' /
            'sourcePath = args(0)' /
            'targetFolder = args(1)' /

            'REM Create Excel application' /
            'Dim excelApp' /
            'Set excelApp = CreateObject("Excel.Application")' /

            'REM Disable Excel alerts' /
            'excelApp.DisplayAlerts = False' /

            'REM Open the source workbook' /
            'Dim workbook' /
            'Set workbook = excelApp.Workbooks.Open(sourcePath)' /

            'REM Loop through each sheet in the workbook' /
            'Dim sheet, sheetName, targetPath' /
            'For Each sheet In workbook.Sheets' /
            '    sheetName = sheet.Name' /
            '    REM Set the target path for each sheet' /
            '    targetPath = targetFolder + "\" + sheetName + ".csv"' /
            '    REM Save the sheet as CSV' /
            '    sheet.SaveAs targetPath, 6 REM 6 refers to the CSV format' /
            'Next' /

            'REM Close the workbook' /
            'workbook.Close False' /

            'REM Quit Excel' /
            'excelApp.Quit' /

            'REM Clean up' /
            'Set sheet = Nothing' /
            'Set workbook = Nothing' /
            'Set excelApp = Nothing' /

            'WScript.Echo "Conversion complete. CSV files saved to " + targetFolder'
            ;
      %mend;
      %gen_vbs();
      %let vbscript_gen_flg=1;
    %end;

  /* create target folder &amp;amp;csv_folder for csv files if not exist */
  %if %sysfunc(fileexist(&amp;amp;csv_folder))=0 %then
    %do;
      data _null_;
        infile %tslit(mkdir "&amp;amp;csv_folder") pipe;
        input;
        put _infile_;
      run;
    %end;
  /* if folder &amp;amp;csv_folder exists: delete any csv file potentially created by an earlier run */
  %else
    %do;
      data _null_;
        infile %tslit(del /Q "&amp;amp;csv_folder\*.csv") pipe;
        input;
        put _infile_;
      run;
    %end;

  /* execute vbs: creates csv files from Excel Workbook under folder &amp;amp;csv_folder */
  data _null_;
    infile %tslit(cscript "&amp;amp;vbscript" "&amp;amp;source_file" "&amp;amp;csv_folder") pipe;
    input;
    put _infile_;
  run;

  /* populate macro vars with names of generated csv files */
  data work.__csv_files;
    infile %tslit(dir /B "&amp;amp;csv_folder\*.csv") pipe truncover end=last;
    input csv_file $35.;
    call symputx(cats('csv_file_',_n_),cats('%nrstr(',csv_file,')'),'l');
    call symputx(cats('out_tbl_',_n_), cats("'",substr(csv_file,1,length(csv_file)-4),"'n"),'l');
    if last then
        call symputx('n_csvfiles',_n_,'l');
  run;

  /** read generated csv files into SAS tables **/
  %do i=1 %to &amp;amp;n_csvfiles;
    /* read csv files into SAS table                                          */
    /* - use proc import to automatically determine required variable lengths */
    /* - read header row as data so all variables become character            */
    proc import 
      datafile=%tslit(&amp;amp;csv_folder\&amp;amp;&amp;amp;csv_file_&amp;amp;i)
      out=work.__csv_data
      dbms=csv
      replace;
      getnames=no;
      datarow=1;
      guessingrows=max;
    run;

    /* populate macro vars with code to rename variables with values from first row (=header from csv file) */
    data _null_;
      set work.__csv_data(obs=1) nobs=__nobs;
      array __charvar{*} _character_;
      do __i=1 to dim(__charvar);
        call symputx(cats('ren_var_',__i),cats(vname(__charvar[__i]),"='",__charvar[__i],"'n"),'l');
      end;
      call symputx('N_ren_var',dim(__charvar),'l');
    run;

    /* create final output table with table and variable names as per Excel sheet */
    /* - skip first obs with header names                                         */
    /* - execute generated code for renaming variables                            */
    data &amp;amp;outlib..&amp;amp;&amp;amp;out_tbl_&amp;amp;i;
      set work.__csv_data;
      if _n_&amp;lt;2 then delete;
      %if %upcase(&amp;amp;delObsAllMissing)=YES %then
        %do;
          if cmiss(of __charvar[*])=dim(__charvar) then delete;
        %end;
      /* generate variable rename code */
      %do k=1 %to &amp;amp;N_ren_var;
        rename &amp;amp;&amp;amp;ren_var_&amp;amp;k;
      %end;
    run;
    proc datasets lib=work nolist nowarn;
      delete __csv_data;
    quit;
  %end;

  /** housekeeping **/
  proc datasets lib=work nolist nowarn;
    delete __csv_files;
  quit;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;If it was me then I'd eventually would still put in a bit more work for a production job and add additional functionality and checks. For example a parameter that allows to request the target tables being created in sub-folders with the name of the Excel workbook.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The potential current "challenge" when creating tables for multiple Excel files is that the same sheet name results in the same table name and though if storing all under the same folder/libref there is a risk that tables get overwritten. Right now provide different librefs for &amp;amp;outlib if there is such a risk.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've already put in some work for testing with special characters like &amp;amp; so they don't create issues (in path, file, tab and column names). I'd put in more unit test work if it was me to release the macro into Test/Prod.&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>Mon, 20 May 2024 07:12:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-an-xlsx-file-preserving-all-characters-as-text-as-they/m-p/928981#M365545</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-20T07:12:02Z</dc:date>
    </item>
  </channel>
</rss>

