<?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: Why is SAS 9.4 converting variable to VAR8? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-is-SAS-9-4-converting-variable-to-VAR8/m-p/826108#M326305</link>
    <description>&lt;P&gt;Concur with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;. Save to a text file, and read it with a DATA step where&amp;nbsp;&lt;EM&gt;you&lt;/EM&gt; have control.&lt;/P&gt;</description>
    <pubDate>Fri, 29 Jul 2022 06:44:55 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-07-29T06:44:55Z</dc:date>
    <item>
      <title>Why is SAS 9.4 converting variable to VAR8?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-is-SAS-9-4-converting-variable-to-VAR8/m-p/825713#M326131</link>
      <description>&lt;P&gt;Hi experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have imported an excel file and the log prints this:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;453 proc import out= info&lt;BR /&gt;454 datafile= "H:\Details.xls"&lt;BR /&gt;455 dbms = xls replace;&lt;BR /&gt;456 getnames= yes;&lt;BR /&gt;457 run;&lt;/P&gt;
&lt;P&gt;NOTE: Variable Name Change. student first name -&amp;gt; student_first__name&lt;BR /&gt;NOTE: Variable Name Change. student last name -&amp;gt; student_last_name&lt;BR /&gt;NOTE: Variable Name Change. stream code -&amp;gt; stream_code&lt;BR /&gt;NOTE: Variable Name Change. gender code -&amp;gt; gender_code&lt;BR /&gt;NOTE: Variable Name Change. status code -&amp;gt; status_code&lt;BR /&gt;NOTE: Variable Name Change. online or/onsite -&amp;gt; online_or_onsite&lt;BR /&gt;NOTE: Variable Name Change. permit to work -&amp;gt; permit_to_work&lt;BR /&gt;NOTE: Variable Name Change. std code AM/AS/AF/EU/SA/GF -&amp;gt;&lt;FONT color="#00FF00"&gt; VAR8&lt;/FONT&gt;&lt;BR /&gt;NOTE: Variable Name Change. comments &lt;BR /&gt;work permit applicabl -&amp;gt; comments___work_permit_applicabl&lt;BR /&gt;NOTE: One or more variables were converted because the data type is not supported by the V9 engine.&lt;BR /&gt;For more details, run with options MSGLEVEL=I.&lt;BR /&gt;NOTE: The import data set has 193 observations and 9 variables.&lt;BR /&gt;NOTE: WORK.INFO data set was successfully created.&lt;BR /&gt;NOTE: PROCEDURE IMPORT used (Total process time):&lt;BR /&gt;real time 0.04 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please help me understand why SAS is converting 'std code AM/AS/AF/EU/SA/GF' variable&amp;nbsp; to &lt;FONT color="#000000"&gt;'&lt;/FONT&gt;&lt;FONT color="#00FF00"&gt;VAR8&lt;FONT color="#000000"&gt;'&lt;/FONT&gt;&lt;/FONT&gt;?How can I force SAS not to do this?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 15:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-is-SAS-9-4-converting-variable-to-VAR8/m-p/825713#M326131</guid>
      <dc:creator>inquistive</dc:creator>
      <dc:date>2022-07-27T15:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: Why is SAS 9.4 converting variable to VAR8?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-is-SAS-9-4-converting-variable-to-VAR8/m-p/825718#M326134</link>
      <description>&lt;P&gt;Save XLS or XLSX to CSV, write a data step to read that format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't have much control over Proc Import. The internal rules in some cases appear to be mystifying at times.&lt;/P&gt;
&lt;P&gt;I have seen similar behavior when there were two or more variables that exceeded 32 characters and the column headings were identical for the first 32 characters.&lt;/P&gt;
&lt;P&gt;By&amp;nbsp; any chance is that column something like a check box or other than standard numeric or character values?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 16:25:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-is-SAS-9-4-converting-variable-to-VAR8/m-p/825718#M326134</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-07-27T16:25:30Z</dc:date>
    </item>
    <item>
      <title>Re: Why is SAS 9.4 converting variable to VAR8?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-is-SAS-9-4-converting-variable-to-VAR8/m-p/825721#M326136</link>
      <description>&lt;P&gt;When an Excel file (XLS) column header contains three or more /'s (or special characters I suppose) the SAS Excel parser 'gives up' and just names the imported column VAR&amp;lt;N&amp;gt;.&amp;nbsp;&amp;nbsp;The variables labels will maintain the original value of the header cell.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can import the columns as-is by using&lt;/P&gt;
&lt;PRE&gt;OPTION VALIDVARNAME=ANY;
&lt;/PRE&gt;
&lt;P&gt;before the PROC IMPORT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Handwriting code for such an imported data set will be aggravating because you will need to reference variables with name-literals. For example:&lt;/P&gt;
&lt;PRE&gt;'std code AM/AS/AF/EU/SA/GF'N&lt;/PRE&gt;
&lt;P&gt;If you use only Enterprise Guide or some other UI client, name-literals will be less of an issue.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 16:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-is-SAS-9-4-converting-variable-to-VAR8/m-p/825721#M326136</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2022-07-27T16:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Why is SAS 9.4 converting variable to VAR8?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-is-SAS-9-4-converting-variable-to-VAR8/m-p/826055#M326284</link>
      <description>&lt;P&gt;It's a standard character variable.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="inquistive_1-1659040880769.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73866iF8AA6CC19565A922/image-size/medium?v=v2&amp;amp;px=400" role="button" title="inquistive_1-1659040880769.png" alt="inquistive_1-1659040880769.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 20:41:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-is-SAS-9-4-converting-variable-to-VAR8/m-p/826055#M326284</guid>
      <dc:creator>inquistive</dc:creator>
      <dc:date>2022-07-28T20:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Why is SAS 9.4 converting variable to VAR8?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-is-SAS-9-4-converting-variable-to-VAR8/m-p/826090#M326294</link>
      <description>&lt;P&gt;That is some decision that PROC IMPORT is making that you have no control over.&lt;/P&gt;
&lt;P&gt;You can always fix it yourself after the fact.&amp;nbsp; Here is an example for how to implement the algorithm used by&amp;nbsp;&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;&amp;nbsp;to create unique standard SAS names from column headers on the results of PROC IMPORT of an Excel file.&lt;/P&gt;
&lt;P&gt;Since you didn't provide any example input I made up one:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1659059612313.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73875iCE43C82548C61811/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1659059612313.png" alt="Tom_0-1659059612313.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;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import file='c:\downloads\test1.xlsx' dbms=xlsx
  out=xlsx replace
;
run;

proc transpose data=xlsx(obs=0) out=names;
  var _all_;
run;

data fixed;
  length varnum 8 name upcase $32 suffix 8 label $256 _name_ $32 _label_ $256 ;
  set names ;
  varnum+1;
  label=compbl(translate(_label_,'   ','090A0D'x));
  if _n_=1 then do;
    declare hash h ();
    h.definekey('upcase','suffix');
    h.definedone();
  end;
  upcase=cats('VAR',varnum);
  if nvalid(coalescec(name,label,upcase)) then name=coalescec(name,label,upcase);
  else do;
* Replace adjacent non-valid characters with single underscore ;
    name=translate(trim(prxchange('s/([^a-zA-Z0-9]+)/ /',-1,coalescec(name,label,upcase))),' _','_ ');
    name=prxchange('s/(^[0-9])/_$1/',1,name);
  end;
  upcase=upcase(name);
  do suffix=0 to 1E4 while( h.add()
     or (suffix and not h.check(key:substrn(catx('_',upcase,suffix),1,32),key:0)))
  ;
     upcase=substr(upcase,1,32-length(cats(suffix))-1);
  end;
  if suffix then substr(name,lengthn(upcase)+1)=cats('_',suffix);
  if name=label then label=' ';
run;

proc sql noprint;
  select case when (upcase(name)=upcase(_name_)) then ' '
         else catx('=',nliteral(_name_),nliteral(name)) end
       , catx('=',nliteral(_name_),quote(trim(label),"'"))
    into :rename separated by ' ' 
       , :label separated by ' '
    from fixed
  ;
%let nrename=&amp;amp;sqlobs;
quit;

proc datasets nolist lib=work;
  modify xlsx ;
    label &amp;amp;label;
    rename &amp;amp;rename;
  run;
quit;

proc contents data=xlsx varnum;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                                   Variables in Creation Order

#    Variable                           Type    Len    Format    Label

1    student_first_name                 Num       8    BEST.     student first name
2    student_last_name                  Num       8    BEST.     student last name
3    stream_code                        Num       8    BEST.     stream code
4    gender_code                        Num       8    BEST.     gender code
5    status_code                        Num       8    BEST.     status code
6    online_or_onsite                   Num       8    BEST.     online or/onsite
7    permit_to_work                     Num       8    BEST.     permit to work
8    std_code_AM_AS_AF_EU_SA_GF         Num       8    BEST.     std code AM/AS/AF/EU/SA/GF
9    comments_work_permit_applicable    Num       8    BEST.     comments work permit applicable
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2022 19:45:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-is-SAS-9-4-converting-variable-to-VAR8/m-p/826090#M326294</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-29T19:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: Why is SAS 9.4 converting variable to VAR8?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-is-SAS-9-4-converting-variable-to-VAR8/m-p/826108#M326305</link>
      <description>&lt;P&gt;Concur with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;. Save to a text file, and read it with a DATA step where&amp;nbsp;&lt;EM&gt;you&lt;/EM&gt; have control.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2022 06:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-is-SAS-9-4-converting-variable-to-VAR8/m-p/826108#M326305</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-07-29T06:44:55Z</dc:date>
    </item>
  </channel>
</rss>

