<?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: Prevent SAS to convert character variables into numeric while PROC IMPORT in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Prevent-SAS-to-convert-character-variables-into-numeric-while/m-p/971489#M43422</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134532"&gt;@NewUsrStat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you very much for your explanation. I tried converting the Excel file into a CSV, but some variable names became "VAR*". I have to say that the variable names contain special characters.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If the columns headers in a CSV file are not valid SAS names then how PROC IMPORT handles them depends on the setting of the VALIDVARNAME= system option.&amp;nbsp; With valid varname=V7 it will generally replace the strange characters with underscores.&amp;nbsp; With VALIDVARNAME=ANY it will use them and then in your SAS code you will need to use names literal (values like 'My var'n ) to reference the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the problem of names becoming just VAR is usually caused by having more fields in the data lines than were in the header row. So you have data in column 5 but only headers for columns 1 to 4.&amp;nbsp; Or it could be that the header row was longer then 32K bytes as that is the limit that PROC IMPORT can support. Or it might be that the column headers are too long and are not unique in the first 32 bytes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have that problem try using a different tool to guess how to read the CSV file. Such as this one:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/csv2ds.sas" target="_blank" rel="noopener"&gt;https://github.com/sasutils/macros/blob/master/csv2ds.sas&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;Differences from PROC IMPORT
- Supports header lines with more than 32,767 characters
- Supports ZIP and GZIP source files
- Generates unique variable names by adding numeric suffix
- Does not overestimate maxlength when longest value is quoted
- Does NOT force character type if all values are quoted
- Generates label when generated variable name is different than header
- Supports NAMEROW option
- Supports numeric fields with special missing values (MISSING statement)
- Does not attach unneeded informats or formats
- Allows overriding calculated metadata
- Allow using random sample of rows to guess metadata
- Generates more compact SAS code
- Generates analysis summary dataset and raw data view
- Saves generated SAS code to a file
- Forces DATE and DATETIME formats to show century
- Difference in generated V7 compatible variable names
  - Replaces adjacent non-valid characters with single underscore&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Jul 2025 19:38:53 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-07-25T19:38:53Z</dc:date>
    <item>
      <title>Prevent SAS to convert character variables into numeric while PROC IMPORT</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Prevent-SAS-to-convert-character-variables-into-numeric-while/m-p/971479#M43416</link>
      <description>&lt;P&gt;Dear all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm experiencing issues while reading an Excel file in input with PROC IMPORT.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sas converts character variables into numeric ones with al lot of missing values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried different ways to overcome this issue but without success, like: to set to UTF-9 the encoding, to specify the variable that is character (although there are many variables to specify).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import out= work.myw replace
  dbms=xlsx  datafile= "...\myfile.xlsx" ;
run;

DBDSOPTS= "DBTYPE=(varx='CHAR(3)')";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help me please?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jul 2025 15:09:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Prevent-SAS-to-convert-character-variables-into-numeric-while/m-p/971479#M43416</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2025-07-25T15:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: Prevent SAS to convert character variables into numeric while PROC IMPORT</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Prevent-SAS-to-convert-character-variables-into-numeric-while/m-p/971481#M43417</link>
      <description>Save as csv and read with a DATA step. The easiest method to get full control over the process.</description>
      <pubDate>Fri, 25 Jul 2025 16:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Prevent-SAS-to-convert-character-variables-into-numeric-while/m-p/971481#M43417</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-07-25T16:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: Prevent SAS to convert character variables into numeric while PROC IMPORT</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Prevent-SAS-to-convert-character-variables-into-numeric-while/m-p/971482#M43418</link>
      <description>&lt;P&gt;SAS &lt;STRONG&gt;does not convert columns in an Excel spreadsheet&lt;/STRONG&gt; into numeric variables unless there is at least one numeric cell in the column and no character cells.&amp;nbsp;&lt;STRONG&gt; If the column has any character cells then it will defined as character.&lt;/STRONG&gt;&amp;nbsp;This is because you can always make a reasonable representation of a number as a character string, but the reverse is not possible.&amp;nbsp; For example, what number would you assign for a cell with the value "NY TIMES"?&amp;nbsp; Note also that it will define an empty column as a character variable with a storage length of 1 (probably because it will take less space than defining it as numeric).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps your issue is with whatever process created the Excel spreadsheet.&amp;nbsp; That is probably where the the cells were made as numeric instead of character.&amp;nbsp; For example if you let Excel open a CSV file without checking what it does it will convert strings that only contain digits into numbers.&amp;nbsp; So an id value like 123 , or worse one with leading zeros, will be converted into a number.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jul 2025 01:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Prevent-SAS-to-convert-character-variables-into-numeric-while/m-p/971482#M43418</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-07-26T01:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Prevent SAS to convert character variables into numeric while PROC IMPORT</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Prevent-SAS-to-convert-character-variables-into-numeric-while/m-p/971483#M43419</link>
      <description>Thank you very much for your explanation. I tried converting the Excel file into a CSV, but some variable names became "VAR*". I have to say that the variable names contain special characters.</description>
      <pubDate>Fri, 25 Jul 2025 18:14:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Prevent-SAS-to-convert-character-variables-into-numeric-while/m-p/971483#M43419</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2025-07-25T18:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: Prevent SAS to convert character variables into numeric while PROC IMPORT</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Prevent-SAS-to-convert-character-variables-into-numeric-while/m-p/971484#M43420</link>
      <description>&lt;P&gt;If you have variable names with special characters, try adding the following option before importing the CSV file:&lt;/P&gt;
&lt;P&gt;options validvarname=any;&lt;/P&gt;
&lt;P&gt;If you have additional questions, please include the code you are currently using.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jul 2025 17:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Prevent-SAS-to-convert-character-variables-into-numeric-while/m-p/971484#M43420</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2025-07-25T17:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: Prevent SAS to convert character variables into numeric while PROC IMPORT</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Prevent-SAS-to-convert-character-variables-into-numeric-while/m-p/971485#M43421</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134532"&gt;@NewUsrStat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you very much for your explanation. I tried converting the Excel file into a CSV, but some variable names became "VAR*". I have to say that the variable names contain special characters.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This does not matter. In the DATA step you write, you will skip the header with FIRSTOBS=2 in the INFILE statement, and name the variables in the INPUT statement yourself.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jul 2025 18:18:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Prevent-SAS-to-convert-character-variables-into-numeric-while/m-p/971485#M43421</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-07-25T18:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Prevent SAS to convert character variables into numeric while PROC IMPORT</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Prevent-SAS-to-convert-character-variables-into-numeric-while/m-p/971489#M43422</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134532"&gt;@NewUsrStat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you very much for your explanation. I tried converting the Excel file into a CSV, but some variable names became "VAR*". I have to say that the variable names contain special characters.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If the columns headers in a CSV file are not valid SAS names then how PROC IMPORT handles them depends on the setting of the VALIDVARNAME= system option.&amp;nbsp; With valid varname=V7 it will generally replace the strange characters with underscores.&amp;nbsp; With VALIDVARNAME=ANY it will use them and then in your SAS code you will need to use names literal (values like 'My var'n ) to reference the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the problem of names becoming just VAR is usually caused by having more fields in the data lines than were in the header row. So you have data in column 5 but only headers for columns 1 to 4.&amp;nbsp; Or it could be that the header row was longer then 32K bytes as that is the limit that PROC IMPORT can support. Or it might be that the column headers are too long and are not unique in the first 32 bytes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have that problem try using a different tool to guess how to read the CSV file. Such as this one:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/csv2ds.sas" target="_blank" rel="noopener"&gt;https://github.com/sasutils/macros/blob/master/csv2ds.sas&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;Differences from PROC IMPORT
- Supports header lines with more than 32,767 characters
- Supports ZIP and GZIP source files
- Generates unique variable names by adding numeric suffix
- Does not overestimate maxlength when longest value is quoted
- Does NOT force character type if all values are quoted
- Generates label when generated variable name is different than header
- Supports NAMEROW option
- Supports numeric fields with special missing values (MISSING statement)
- Does not attach unneeded informats or formats
- Allows overriding calculated metadata
- Allow using random sample of rows to guess metadata
- Generates more compact SAS code
- Generates analysis summary dataset and raw data view
- Saves generated SAS code to a file
- Forces DATE and DATETIME formats to show century
- Difference in generated V7 compatible variable names
  - Replaces adjacent non-valid characters with single underscore&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jul 2025 19:38:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Prevent-SAS-to-convert-character-variables-into-numeric-while/m-p/971489#M43422</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-07-25T19:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: Prevent SAS to convert character variables into numeric while PROC IMPORT</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Prevent-SAS-to-convert-character-variables-into-numeric-while/m-p/971510#M43423</link>
      <description>&lt;A href="https://communities.sas.com/t5/SAS-Programming/Proc-Import-with-variable-type-specifications-0D-0A/m-p/971395#M377313" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Proc-Import-with-variable-type-specifications-0D-0A/m-p/971395#M377313&lt;/A&gt;</description>
      <pubDate>Sat, 26 Jul 2025 04:47:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Prevent-SAS-to-convert-character-variables-into-numeric-while/m-p/971510#M43423</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-07-26T04:47:39Z</dc:date>
    </item>
  </channel>
</rss>

