<?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: import excel file with numbers in column headings in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76270#M22114</link>
    <description>&amp;gt; How they will be handled in the rest of the program&lt;BR /&gt;
&amp;gt;  remains to be seen!&lt;BR /&gt;
&lt;BR /&gt;
Rename them and set validvarname back to V7...&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
options validvarname=any;&lt;BR /&gt;
data test;&lt;BR /&gt;
   length '1results'n '2results'n '3results'n '444Resu'n 8;&lt;BR /&gt;
   set sashelp.class;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
   select &lt;BR /&gt;
      cats&lt;BR /&gt;
         (&lt;BR /&gt;
            nliteral(name),&lt;BR /&gt;
            '=',&lt;BR /&gt;
            substr(name,anyalpha(name)),&lt;BR /&gt;
            substr(name,1,anyalpha(name)-1)&lt;BR /&gt;
         )&lt;BR /&gt;
      into :rename separated by ' '&lt;BR /&gt;
   from dictionary.columns&lt;BR /&gt;
   where libname eq 'WORK' and memname eq 'TEST' and anydigit(name) eq 1;&lt;BR /&gt;
      &lt;BR /&gt;
   quit;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc datasets;&lt;BR /&gt;
   modify test;&lt;BR /&gt;
   rename &amp;amp;rename;&lt;BR /&gt;
   run;&lt;BR /&gt;
   contents data=test short;&lt;BR /&gt;
   quit;&lt;BR /&gt;
options validvarname=v7;&lt;BR /&gt;
[/pre]</description>
    <pubDate>Wed, 21 Oct 2009 17:36:16 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2009-10-21T17:36:16Z</dc:date>
    <item>
      <title>import excel file with numbers in column headings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76266#M22110</link>
      <description>I have data something like this:&lt;BR /&gt;
&lt;BR /&gt;
SampleID    1result     2result    3result&lt;BR /&gt;
A                  0.9           0.4         1.2&lt;BR /&gt;
B                  0.3           0.6          0.8&lt;BR /&gt;
C                  0.2           0.7          2.3&lt;BR /&gt;
&lt;BR /&gt;
Which are in excel.  I am very familiar with using the libname statement method to bring an excel file into SAS.  BUT, as you can see the column names have leading numbers.  Which SAS replaces with an _ at the time of import.  This is problematic because I then lose the only identifying piece of information about that column.  If SAS were to put a leading underscore in FRONT of the number, and not replace the number, that would be fine.&lt;BR /&gt;
&lt;BR /&gt;
These data are coming directly from a laboratory instrument, and I am assured by the tecnicians that the column headings cannot be changed.&lt;BR /&gt;
&lt;BR /&gt;
So, besides editing every excel file prior to import, is there a way to bring in the data from excel and not lose the useful column information?  There are many, many of these excel files.......&lt;BR /&gt;
&lt;BR /&gt;
Thank you, &lt;BR /&gt;
&lt;BR /&gt;
NWV</description>
      <pubDate>Tue, 20 Oct 2009 19:33:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76266#M22110</guid>
      <dc:creator>NWV</dc:creator>
      <dc:date>2009-10-20T19:33:44Z</dc:date>
    </item>
    <item>
      <title>Re: import excel file with numbers in column headings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76267#M22111</link>
      <description>input SampleID $ '1result'n '2result'n.....&lt;BR /&gt;
&lt;BR /&gt;
the syntax '...'n treats the string as a literal therefore allows you to use it as a variable name.&lt;BR /&gt;
&lt;BR /&gt;
You better rename these variables later on or you will have the same issue over and over.&lt;BR /&gt;
i.e. rename '1result'n = _1result;&lt;BR /&gt;
&lt;BR /&gt;
...Ooops, sorry, didn't read your post good enough:&lt;BR /&gt;
For a fast solution: Use the import wizard in SAS EG and you will get what you need.&lt;BR /&gt;
The code generated by the import wizard will also give you some ideas how to solve this issue.&lt;BR /&gt;
&lt;BR /&gt;
Also worth a try might be options validvarname=any; (not sure if this will have any effect).&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Patrick</description>
      <pubDate>Tue, 20 Oct 2009 21:40:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76267#M22111</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-10-20T21:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: import excel file with numbers in column headings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76268#M22112</link>
      <description>If you import the data from an Excel sheet formatted like you have it in your post this should work.  It uses the label name with a character in front of it to rename the column.  Assuming your first column will always be 'SampleID' the macro skips that column.&lt;BR /&gt;
&lt;BR /&gt;
I modified a macro outlined in the SUGI paper at this link:&lt;BR /&gt;
www2.sas.com/proceedings/sugi28/118-28.pdf&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
PROC IMPORT DATAFILE="C:\TEST.XLS"&lt;BR /&gt;
OUT=TEST&lt;BR /&gt;
REPLACE&lt;BR /&gt;
DBMS = EXCEL ;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
options macrogen mprint mlogic;&lt;BR /&gt;
%macro rename(lib=,dsn=);&lt;BR /&gt;
options pageno=1 nodate;&lt;BR /&gt;
proc contents data=&amp;amp;lib..&amp;amp;dsn;&lt;BR /&gt;
title "Before Renaming All Variables";&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
select nvar-1 into :num_vars&lt;BR /&gt;
from dictionary.tables&lt;BR /&gt;
where libname="&amp;amp;LIB" and&lt;BR /&gt;
memname="&amp;amp;DSN";&lt;BR /&gt;
select distinct NAME into :var1-&lt;BR /&gt;
:var%TRIM(%LEFT(&amp;amp;num_vars))&lt;BR /&gt;
from dictionary.columns&lt;BR /&gt;
where libname="&amp;amp;LIB" and&lt;BR /&gt;
memname="&amp;amp;DSN" and name ne "SampleID";&lt;BR /&gt;
&lt;BR /&gt;
select distinct %trim("A"||label) into :lvar1-&lt;BR /&gt;
:lvar%TRIM(%LEFT(&amp;amp;num_vars))&lt;BR /&gt;
from dictionary.columns&lt;BR /&gt;
where libname="&amp;amp;LIB" and&lt;BR /&gt;
memname="&amp;amp;DSN" and name ne "SampleID";&lt;BR /&gt;
&lt;BR /&gt;
quit;&lt;BR /&gt;
run;&lt;BR /&gt;
proc datasets library=&amp;amp;LIB;&lt;BR /&gt;
modify &amp;amp;DSN;&lt;BR /&gt;
rename&lt;BR /&gt;
%do i=1 %to &amp;amp;num_vars;&lt;BR /&gt;
&amp;amp;&amp;amp;var&amp;amp;i=&amp;amp;&amp;amp;Lvar&amp;amp;i.&lt;BR /&gt;
%end;&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
run;&lt;BR /&gt;
options pageno=1 nodate;&lt;BR /&gt;
proc contents data=&amp;amp;lib..&amp;amp;dsn;&lt;BR /&gt;
title "After Renaming All Variables";&lt;BR /&gt;
run;&lt;BR /&gt;
%mend rename;&lt;BR /&gt;
%rename(lib=WORK,dsn=TEST);</description>
      <pubDate>Tue, 20 Oct 2009 22:46:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76268#M22112</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-20T22:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: import excel file with numbers in column headings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76269#M22113</link>
      <description>Well, the options validvarname=any worked to bring the column headers in just fine with leading numbers.  How they will be handled in the rest of the program remains to be seen!&lt;BR /&gt;
&lt;BR /&gt;
Thank you so much for the suggestions.</description>
      <pubDate>Wed, 21 Oct 2009 12:49:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76269#M22113</guid>
      <dc:creator>NWV</dc:creator>
      <dc:date>2009-10-21T12:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: import excel file with numbers in column headings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76270#M22114</link>
      <description>&amp;gt; How they will be handled in the rest of the program&lt;BR /&gt;
&amp;gt;  remains to be seen!&lt;BR /&gt;
&lt;BR /&gt;
Rename them and set validvarname back to V7...&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
options validvarname=any;&lt;BR /&gt;
data test;&lt;BR /&gt;
   length '1results'n '2results'n '3results'n '444Resu'n 8;&lt;BR /&gt;
   set sashelp.class;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
   select &lt;BR /&gt;
      cats&lt;BR /&gt;
         (&lt;BR /&gt;
            nliteral(name),&lt;BR /&gt;
            '=',&lt;BR /&gt;
            substr(name,anyalpha(name)),&lt;BR /&gt;
            substr(name,1,anyalpha(name)-1)&lt;BR /&gt;
         )&lt;BR /&gt;
      into :rename separated by ' '&lt;BR /&gt;
   from dictionary.columns&lt;BR /&gt;
   where libname eq 'WORK' and memname eq 'TEST' and anydigit(name) eq 1;&lt;BR /&gt;
      &lt;BR /&gt;
   quit;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc datasets;&lt;BR /&gt;
   modify test;&lt;BR /&gt;
   rename &amp;amp;rename;&lt;BR /&gt;
   run;&lt;BR /&gt;
   contents data=test short;&lt;BR /&gt;
   quit;&lt;BR /&gt;
options validvarname=v7;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 21 Oct 2009 17:36:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76270#M22114</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-10-21T17:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: import excel file with numbers in column headings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76271#M22115</link>
      <description>"wondrous to be..."&lt;BR /&gt;
nLiteral()&lt;BR /&gt;
is new to me and looks to be very useful...&lt;BR /&gt;
A quick check on an  "outsize" name string returned an name literal that's longer. &lt;BR /&gt;
The SASlog demonstrates an issue&lt;BR /&gt;
[pre]52   data t;&lt;BR /&gt;
53     name = nliteral("Thought w'ld try a string of arbiTrary $length OK?"   );&lt;BR /&gt;
54     put name= ;&lt;BR /&gt;
55     call symput( 'name', name ) ;&lt;BR /&gt;
56   run;&lt;BR /&gt;
&lt;BR /&gt;
name="Thought w'ld try a string of arbiTrary $length OK?"N&lt;BR /&gt;
NOTE: The data set WORK.T has 1 observations and 1 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.01 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
57   option validVarName= any ;&lt;BR /&gt;
58   data trouble ;&lt;BR /&gt;
59     set t ;&lt;BR /&gt;
60     &amp;amp;name= name ;&lt;BR /&gt;
ERROR: The variable named Thought w'ld try a string of arbiTrary $length OK? contains more than 32 characters.&lt;BR /&gt;
61   run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: The SAS System stopped processing this step because of errors.[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Is this behaviour to tolerate or recommend for "improvement"&lt;BR /&gt;
 &lt;BR /&gt;
PeterC</description>
      <pubDate>Thu, 22 Oct 2009 12:29:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76271#M22115</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-10-22T12:29:45Z</dc:date>
    </item>
    <item>
      <title>Re: import excel file with numbers in column headings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76272#M22116</link>
      <description>You have demonstrated that NLITERAL does not know anything about valid SAS names, and seems to be more of a special version of QUOTE function.&lt;BR /&gt;
&lt;BR /&gt;
I guess you need to futher examine the result with NVALID function.&lt;BR /&gt;
&lt;BR /&gt;
I would like a function that "transforms" a string into a valid SAS name.&lt;BR /&gt;
&lt;BR /&gt;
But I reckon that could be accomplished with ANYFIRST/NOTFIRST and ANYNAME/NOTNAME

Message was edited by: data _null_;</description>
      <pubDate>Thu, 22 Oct 2009 13:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76272#M22116</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-10-22T13:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: import excel file with numbers in column headings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76273#M22117</link>
      <description>Another part of the valid-name-generation exercise requires information from elsewhere: &lt;BR /&gt;
To be valid,  a name must be unique in the context where it is used . ......&lt;BR /&gt;
......&lt;BR /&gt;
must be a way .... &lt;BR /&gt;
effective, needs simple packaging, like nValid() and nLiteral() functions indicate is very close by......&lt;BR /&gt;
I just don't want to start building hashtables to store and search for generated names.&lt;BR /&gt;
Somewhere SAS has internally packaged the unique-name-management, for example, for access and import routines, that handle column names of "varying quality" &lt;BR /&gt;
... ... ... hopefully we'll be informed by some "little birdie" if it might be on someone-else's wish-list ....&lt;BR /&gt;
 &lt;BR /&gt;
PeterC</description>
      <pubDate>Thu, 22 Oct 2009 14:10:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76273#M22117</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-10-22T14:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: import excel file with numbers in column headings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76274#M22118</link>
      <description>I have seen the rules referred to as "variable name normalization rules" and they are dependent on the setting of the VALIDVARNAME system option.  As you suggest it would "nice" to have a callable form.  I guess we will have to call on our "old friend" the macro language.&lt;BR /&gt;
&lt;BR /&gt;
Cut from docs &lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
SAS/ACCESS Specific Details &lt;BR /&gt;
 &lt;BR /&gt;
VALIDVARNAME= enables you to control which rules apply for SAS variable&lt;BR /&gt;
names. For more information about the VALIDVARNAME= system option, see the &lt;BR /&gt;
SAS Language Reference: Dictionary. The settings are as follows:&lt;BR /&gt;
 &lt;BR /&gt;
VALIDVARNAME=V7 &lt;BR /&gt;
indicates that a DBMS column name is changed to a valid SAS name by using &lt;BR /&gt;
the following rules:&lt;BR /&gt;
 &lt;BR /&gt;
Up to 32 mixed-case alphanumeric characters are allowed.&lt;BR /&gt;
 &lt;BR /&gt;
Names must begin with an alphabetic character or an underscore.&lt;BR /&gt;
 &lt;BR /&gt;
Invalid characters are changed to underscores.&lt;BR /&gt;
 &lt;BR /&gt;
Any column name that is not unique when it is normalized is made unique by &lt;BR /&gt;
appending a counter (0,1,2,...) to the name.&lt;BR /&gt;
 &lt;BR /&gt;
This is the default value for SAS Version 7 and later. &lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 22 Oct 2009 18:22:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/import-excel-file-with-numbers-in-column-headings/m-p/76274#M22118</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-10-22T18:22:18Z</dc:date>
    </item>
  </channel>
</rss>

