<?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: Valid Var Name not working and Importing Excel Files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Valid-Var-Name-not-working-and-Importing-Excel-Files/m-p/531460#M145459</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/224356"&gt;@BenCBanks&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am attempting to use this code (see below) to import multiple excel files (more than 100) that should all have the same file format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You will likely be much better off saving all of these to CSV format and writing a data step to read them if they do have the same layout.&lt;/P&gt;
&lt;P&gt;Proc Import guesses for each file such things as variable type, length and informat/formats and uses very few rows to "guess" what attributes to set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Write a data step, or use proc import and a large value for the guessing rows value to generate a data step to read one, setting your desired variable names, lengths formats and informats. You can write a data step to read multiple files at one time, there are multiple examples on this forum.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Jan 2019 18:30:06 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-01-30T18:30:06Z</dc:date>
    <item>
      <title>Valid Var Name not working and Importing Excel Files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Valid-Var-Name-not-working-and-Importing-Excel-Files/m-p/531458#M145457</link>
      <description>&lt;P&gt;I am attempting to use this code (see below) to import multiple excel files (more than 100) that should all have the same file format. However, they are all littered with awful naming conventions, hence the&amp;nbsp;options validvarname=any; option at the top. However, this does not work and I keep on getting errors like about the file name being an invalid SAS name. Like "ERROR: The value 'REPORT_2018-10-20_01-00-04_4'n is not a valid SAS member name"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, on a side note. I do plan on appending all of these files together, whenever I can get this to run appropriately. Would take suggestions on how to make the code better also.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT: I was able to get the member name right, I was confused as to the different between MEMBERNAME and VARNAME. Now, I could still use some pointers on appending the data correctly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know why this is the case? This code is an adaptation of the code I found here:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/General-SAS-Programming/Importing-several-files-into-SAS/td-p/241827" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/General-SAS-Programming/Importing-several-files-into-SAS/td-p/241827&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;filename fref "/pmsdat/Strat/dump" ;

options validvarname=any; /* to allow non-standard dataset names */
 
/* Making a list of all files in the folder */
data FilesInFolder;
   length Line 8 File $300;
   List = dopen('fref');  /* corrected the function argument */
   do Line = 1 to dnum(List);
        File = compress(trim(dread(List,Line)));
        output;
   end;
   drop list line;
run;
 
/* Creating global macro variables */  /* not "local" */
data _NULL_;
     set FilesInFolder end=final;
     call symput(cats('File', _N_), trim(File));     /* used CATS instead of COMPRESS (...||...) */
     call symput(cats('Name', _N_), trim(nliteral(substr(File,1,min(28, length(File)))))); /* inserted */
     if final then call symputx(trim('Total'), _N_); /* replaced symput by symputx */
run;


/* This macro should import all files specified in the list and save them as datasets */
%macro loop;

%do i = 1 %to &amp;amp;Total;

  proc import datafile="/pmsdat/Strat/dump/&amp;amp;&amp;amp;File&amp;amp;i"
       out=WORK.&amp;amp;&amp;amp;name&amp;amp;i  /* adapted */
       dbms=xlsx
	   
       replace;
		sheet="visits";
		getnames=yes;
  run;
%end;
%mend loop;
 
%loop&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 18:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Valid-Var-Name-not-working-and-Importing-Excel-Files/m-p/531458#M145457</guid>
      <dc:creator>BenCBanks</dc:creator>
      <dc:date>2019-01-30T18:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: Valid Var Name not working and Importing Excel Files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Valid-Var-Name-not-working-and-Importing-Excel-Files/m-p/531460#M145459</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/224356"&gt;@BenCBanks&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am attempting to use this code (see below) to import multiple excel files (more than 100) that should all have the same file format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You will likely be much better off saving all of these to CSV format and writing a data step to read them if they do have the same layout.&lt;/P&gt;
&lt;P&gt;Proc Import guesses for each file such things as variable type, length and informat/formats and uses very few rows to "guess" what attributes to set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Write a data step, or use proc import and a large value for the guessing rows value to generate a data step to read one, setting your desired variable names, lengths formats and informats. You can write a data step to read multiple files at one time, there are multiple examples on this forum.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 18:30:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Valid-Var-Name-not-working-and-Importing-Excel-Files/m-p/531460#M145459</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-30T18:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: Valid Var Name not working and Importing Excel Files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Valid-Var-Name-not-working-and-Importing-Excel-Files/m-p/531549#M145497</link>
      <description>&lt;P&gt;VALIDVARNAME is for VARIABLE names.&lt;/P&gt;
&lt;P&gt;VALIDMEMNAME is for MEMBER names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any validmemname=extend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Jan 2019 04:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Valid-Var-Name-not-working-and-Importing-Excel-Files/m-p/531549#M145497</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-01-31T04:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: Valid Var Name not working and Importing Excel Files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Valid-Var-Name-not-working-and-Importing-Excel-Files/m-p/531565#M145508</link>
      <description>&lt;P&gt;Start by getting rid of the Excel files and have the data in text files (csv, tab-separated, fixed-width columns, whatever).&lt;/P&gt;
&lt;P&gt;Once that is done, one data step with a wildcard (or a compound infile) will do all your work, and &lt;EM&gt;you&lt;/EM&gt; will have total control over variable attributes.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 06:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Valid-Var-Name-not-working-and-Importing-Excel-Files/m-p/531565#M145508</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-31T06:40:13Z</dc:date>
    </item>
  </channel>
</rss>

