<?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 Proc Import with variable type specifications%0D%0A in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-with-variable-type-specifications-0D-0A/m-p/971387#M377307</link>
    <description>&lt;P&gt;I'm out of practice with coding and attempting to import data from an Excel file, specifying that all variables should be CHAR (as I'll be appending the new dataset to an existing SAS dataset with CHAR variables).&amp;nbsp; Not sure why the following Proc Import code results in an error:&amp;nbsp; &lt;EM&gt;DBDSOPTS statement not valid or used out of proper order&lt;/EM&gt;.&amp;nbsp; Is there a better way to do this?&amp;nbsp; (SAS Enterprise Guide 8.3).&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc import 
	datafile="\path\filename.xlsx"
	out= NewDataset
	dbms = xlsx
	replace;
	getnames=yes; 
 	DBDSOPTS="DBTYPE=(ID_nbr='CHAR(6)' City ='CHAR(50)')";	
run;

proc append
  base=ExistingDataset data=NewDataset;
  run;  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;The variables in the two dataset will need to match in terms of data type and length before appending.&amp;nbsp; Coding using the Length statement did not work out, either.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 23 Jul 2025 16:33:12 GMT</pubDate>
    <dc:creator>Lani1</dc:creator>
    <dc:date>2025-07-23T16:33:12Z</dc:date>
    <item>
      <title>Proc Import with variable type specifications%0D%0A</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-with-variable-type-specifications-0D-0A/m-p/971387#M377307</link>
      <description>&lt;P&gt;I'm out of practice with coding and attempting to import data from an Excel file, specifying that all variables should be CHAR (as I'll be appending the new dataset to an existing SAS dataset with CHAR variables).&amp;nbsp; Not sure why the following Proc Import code results in an error:&amp;nbsp; &lt;EM&gt;DBDSOPTS statement not valid or used out of proper order&lt;/EM&gt;.&amp;nbsp; Is there a better way to do this?&amp;nbsp; (SAS Enterprise Guide 8.3).&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc import 
	datafile="\path\filename.xlsx"
	out= NewDataset
	dbms = xlsx
	replace;
	getnames=yes; 
 	DBDSOPTS="DBTYPE=(ID_nbr='CHAR(6)' City ='CHAR(50)')";	
run;

proc append
  base=ExistingDataset data=NewDataset;
  run;  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;The variables in the two dataset will need to match in terms of data type and length before appending.&amp;nbsp; Coding using the Length statement did not work out, either.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 16:33:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-with-variable-type-specifications-0D-0A/m-p/971387#M377307</guid>
      <dc:creator>Lani1</dc:creator>
      <dc:date>2025-07-23T16:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import with variable type specifications%0D%0A</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-with-variable-type-specifications-0D-0A/m-p/971395#M377313</link>
      <description>&lt;P&gt;To use the DBDSOPTS, you have to specify DBMS=EXCEL.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import  
out=class2
datafile="c:\temp\class2.xlsx"
dbms=excel replace;
sheet=class2;
dbdsopts="dbsastype=(Age='char(8)' Height='char(8)')";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Another option is to a&lt;SPAN&gt;dd a row at the bottom of each spreadsheet containing a dummy character in each numeric column and import it with DBMS=XLSX engine (MIXED=YES&amp;nbsp;&amp;nbsp;is the default).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 17:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-with-variable-type-specifications-0D-0A/m-p/971395#M377313</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2025-07-23T17:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import with variable type specifications%0D%0A</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-with-variable-type-specifications-0D-0A/m-p/971397#M377314</link>
      <description>&lt;P&gt;If the column headers are text then just tell PROC IMPORT to NOT guess the names.&amp;nbsp; You can then rename the variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC APPEND will only generate a WARNING if the lengths are shorter.&amp;nbsp; And you can use the FORCE option to have it truncate the values when the lengths are longer.&lt;/P&gt;
&lt;P&gt;Make sure to skip the header line.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import 
  dbms = xlsx
  datafile="\path\filename.xlsx"
  out= NewDataset
  replace
;
  getnames=no; 
run;

proc append force
  base=ExistingDataset
  data=NewDataset(firstobs=2 rename=(
      a=ID_nbr b=City
   ))
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to suppress the warning messages then run another step to change the lengths.&amp;nbsp;You could even make that as a VIEW so you don't make an extra copy of the data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create view for_append as
select trim(A) as ID_nbr length=6
     , time(B) as City length=50
from NewDataset(firstobs=2)
;
quit;
proc append force
  base=ExistingDataset
  data=for_append
;
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>Wed, 23 Jul 2025 19:18:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-with-variable-type-specifications-0D-0A/m-p/971397#M377314</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-07-23T19:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import with variable type specifications%0D%0A</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-with-variable-type-specifications-0D-0A/m-p/971400#M377316</link>
      <description>&lt;P&gt;The usual advice also applies here: save the spreadsheet to a text (csv) file and read that with a DATA step, which gives you full control over how the data is read.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 19:24:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-with-variable-type-specifications-0D-0A/m-p/971400#M377316</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-07-23T19:24:09Z</dc:date>
    </item>
  </channel>
</rss>

