<?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: Using macro in proc import with file name ending with a date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794292#M32823</link>
    <description>&lt;PRE&gt;1    /* Macro proc import*/
2    options mprint;
3    %macro import(T01);
4    FILENAME REFFILE "filepath\&amp;amp;T01..xls";
5
6    proc import datafile=refile dbms=xls out=&amp;amp;T01. replace;
7    sheet="sheetname";
8    namerow=7;
9    startrow=10;
10   *Endrow=934 (the end rows are not the same for each table;
11   getnames=yes;
12   run;
13   %mend import;
14
15   %import (filename_2022-01-27);
MPRINT(IMPORT):   FILENAME REFFILE
"filepath\filename_2022-01-27.xls";
NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

NOTE: The SAS System stopped processing this step because of errors.
MPRINT(IMPORT):   proc import datafile=refile dbms=xls out=filename_2022-01-27 replace
sheet="sheetname";
MPRINT(IMPORT):   namerow=7;
MPRINT(IMPORT):   startrow=10;
MPRINT(IMPORT):   *Endrow=934 (the end rows are not the same for each table;
MPRINT(IMPORT):   getnames=yes;
MPRINT(IMPORT):   run;
NOTE: Line generated by the macro variable "T01".
1                filename_2022-01-27
                              ---
                              22
                              200
ERROR 22-322: Syntax error, expecting one of the following: ;, (, DATAFILE, DATATABLE, DBMS, DEBUG,
              FILE, OUT, REPLACE, TABLE, _DEBUG_.

ERROR 200-322: The symbol is not recognized and will be ignored.

16   %import (filename_2022-01-31);
MPRINT(IMPORT):   FILENAME REFFILE
"filepath\filename_2022-01-31.xls";


NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

NOTE: The SAS System stopped processing this step because of errors.
MPRINT(IMPORT):   proc import datafile=refile dbms=xls out=filename_2022-01-31 replace
sheet="sheetname";
MPRINT(IMPORT):   namerow=7;
MPRINT(IMPORT):   startrow=10;
MPRINT(IMPORT):   *Endrow=934 (the end rows are not the same for each table;
MPRINT(IMPORT):   getnames=yes;
MPRINT(IMPORT):   run;
NOTE: Line generated by the macro variable "T01".
1                filename_2022-01-31
                              ---
                              22
                              200
ERROR 22-322: Syntax error, expecting one of the following: ;, (, DATAFILE, DATATABLE, DBMS, DEBUG,
              FILE, OUT, REPLACE, TABLE, _DEBUG_.

ERROR 200-322: The symbol is not recognized and will be ignored.

17   /*etc.*/
18   /*the table name with -01-27, etc. that not work*/
19   run;&lt;/PRE&gt;&lt;P&gt;@&lt;/P&gt;</description>
    <pubDate>Thu, 03 Feb 2022 17:20:18 GMT</pubDate>
    <dc:creator>Didi_b</dc:creator>
    <dc:date>2022-02-03T17:20:18Z</dc:date>
    <item>
      <title>Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794272#M32813</link>
      <description>&lt;P&gt;I would like to import multiple Excel file into SAS using macro. My programm didn't work because my files names are ending with dates. Also my line endrow is different for each excel file. I would like to get some help to succeed please. Excel file name are the same in different excel file, the difference is on date. The sheet name in each Excel file are the same too as the rest except the Endrow. I can't change the Excel files name because there are a lot of them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here my program :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro import(R01);&lt;BR /&gt;FILENAME REFFILE "filepath\&amp;amp;T01..xls";&lt;/P&gt;&lt;P&gt;proc import datafile=refile dbms=xls out=&amp;amp;T01. replace;&lt;BR /&gt;sheet="sheetname";&lt;BR /&gt;namerow=7;&lt;BR /&gt;startrow=10;&lt;BR /&gt;*Endrow=934 (the end rows are not the same for each table how could I fix that;&lt;BR /&gt;getnames=yes;&lt;BR /&gt;run;&lt;BR /&gt;%mend import;&lt;/P&gt;&lt;P&gt;%import (filename_2022-01-27);&lt;BR /&gt;%import (filename_2022-01-31);&lt;BR /&gt;/*etc.*/&lt;BR /&gt;/*the table name with -01-27, etc. not working*/&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 16:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794272#M32813</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-02-03T16:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794273#M32814</link>
      <description>Correction :&lt;BR /&gt;&lt;BR /&gt;%macro import(T01);&lt;BR /&gt;FILENAME REFFILE "filepath\&amp;amp;T01..xls";&lt;BR /&gt;&lt;BR /&gt;proc import datafile=refile dbms=xls out=&amp;amp;T01. replace;&lt;BR /&gt;sheet="sheetname";&lt;BR /&gt;namerow=7;&lt;BR /&gt;startrow=10;&lt;BR /&gt;*Endrow=934 (the end rows are not the same for each table how could I fix that;&lt;BR /&gt;getnames=yes;&lt;BR /&gt;run;&lt;BR /&gt;%mend import;&lt;BR /&gt;&lt;BR /&gt;%import (filename_2022-01-27);&lt;BR /&gt;%import (filename_2022-01-31);&lt;BR /&gt;/*etc.*/&lt;BR /&gt;/*the table name with -01-27, etc. not working*/&lt;BR /&gt;run;</description>
      <pubDate>Thu, 03 Feb 2022 16:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794273#M32814</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-02-03T16:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794279#M32815</link>
      <description>&lt;P&gt;When you have errors in the log, you need to show us the ENTIRE log for this macro. Do not show us tiny portions of the log, we need to see ALL of it for this macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to turn on the macro debugging options, by running the next command, and then run the code again.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please copy the log as text and paste it into the window that appears when you click on the &amp;lt;/&amp;gt; icon.&amp;nbsp;&lt;STRONG&gt;DO NOT SKIP THIS STEP.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Insert Log Icon in SAS Communities.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66171iFEC370B1DBF07B28/image-size/large?v=v2&amp;amp;px=999" role="button" title="Insert Log Icon in SAS Communities.png" alt="Insert Log Icon in SAS Communities.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 16:56:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794279#M32815</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-02-03T16:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794281#M32816</link>
      <description>&lt;P&gt;It appears that your error is here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;out=&amp;amp;T01.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When you use macro variables, they are replaced by their value when you run the code. And whatever the replacement values are MUST create legal valid working code. So, the first run produces this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;out=filename_2022-01-27&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is this legal SAS code, or is there a problem here? Can a data set name have hyphens in it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In order to improve your macro writing, you need to first (FIRST!) have legal valid working SAS code without macros and without macro variables. Had you done this, you would most likely have avoided this issue.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 16:59:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794281#M32816</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-02-03T16:59:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794282#M32817</link>
      <description>&lt;P&gt;Are you sure those are XLS files and not XLSX?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may need to carefully check which character is separating the digits in that "date" portion. You might be coding with a simple "dash" character from the keyboard but some may have named the file with a different character that looks like a dash.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might consider searching this forum for the approaches that search folders and use the actual file names to import.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Caution:&lt;/STRONG&gt; If all of these files are supposed to have the same structure and you intend to combine them at any point you really should not rely on Proc Import as every single file gets examined and imported separately. Which often leads to variables of different lengths or types. Not only that only the first few rows are examined and if you have longer values at the end of the file the values could be truncated because the shorter ones were at the top of the file. This is especially a concern if some columns are sparsely populated.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 17:07:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794282#M32817</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-03T17:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794289#M32821</link>
      <description>&lt;PRE&gt;1    /* Macro proc import*/
2    options mprint;
3    %macro import(T01);
4    FILENAME REFFILE "filepath\&amp;amp;T01..xls";
5
6    proc import datafile=refile dbms=xls out=&amp;amp;T01. replace;
7    sheet="sheetname";
8    namerow=7;
9    startrow=10;
10   *Endrow=934 (the end rows are not the same for each table;
11   getnames=yes;
12   run;
13   %mend import;
14
15   %import (filename_2022-01-27);
MPRINT(IMPORT):   FILENAME REFFILE
"filepath\filename_2022-01-27.xls";
NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

NOTE: The SAS System stopped processing this step because of errors.
MPRINT(IMPORT):   proc import datafile=refile dbms=xls out=filename_2022-01-27 replace
sheet="sheetname";
MPRINT(IMPORT):   namerow=7;
MPRINT(IMPORT):   startrow=10;
MPRINT(IMPORT):   *Endrow=934 (the end rows are not the same for each table;
MPRINT(IMPORT):   getnames=yes;
MPRINT(IMPORT):   run;
NOTE: Line generated by the macro variable "T01".
1    filename_2022-01-27
                              ---
                              22
                              200
ERROR 22-322: Syntax error, expecting one of the following: ;, (, DATAFILE, DATATABLE, DBMS, DEBUG,
              FILE, OUT, REPLACE, TABLE, _DEBUG_.

ERROR 200-322: The symbol is not recognized and will be ignored.

16   %import (filename_2022-01-31);
MPRINT(IMPORT):   FILENAME REFFILE
"filepath\filename_2022-01-31.xls";


NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

NOTE: The SAS System stopped processing this step because of errors.
MPRINT(IMPORT):   proc import datafile=refile dbms=xls out=filename_2022-01-31 replace
sheet="sheetname";
MPRINT(IMPORT):   namerow=7;
MPRINT(IMPORT):   startrow=10;
MPRINT(IMPORT):   *Endrow=934 (the end rows are not the same for each table;
MPRINT(IMPORT):   getnames=yes;
MPRINT(IMPORT):   run;
NOTE: Line generated by the macro variable "T01".
1    filename_2022-01-31
                              ---
                              22
                              200
ERROR 22-322: Syntax error, expecting one of the following: ;, (, DATAFILE, DATATABLE, DBMS, DEBUG,
              FILE, OUT, REPLACE, TABLE, _DEBUG_.

ERROR 200-322: The symbol is not recognized and will be ignored.

17   /*etc.*/
18   /*the table name with -01-27, etc. that not work*/
19   run;


&lt;/PRE&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 17:13:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794289#M32821</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-02-03T17:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794292#M32823</link>
      <description>&lt;PRE&gt;1    /* Macro proc import*/
2    options mprint;
3    %macro import(T01);
4    FILENAME REFFILE "filepath\&amp;amp;T01..xls";
5
6    proc import datafile=refile dbms=xls out=&amp;amp;T01. replace;
7    sheet="sheetname";
8    namerow=7;
9    startrow=10;
10   *Endrow=934 (the end rows are not the same for each table;
11   getnames=yes;
12   run;
13   %mend import;
14
15   %import (filename_2022-01-27);
MPRINT(IMPORT):   FILENAME REFFILE
"filepath\filename_2022-01-27.xls";
NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

NOTE: The SAS System stopped processing this step because of errors.
MPRINT(IMPORT):   proc import datafile=refile dbms=xls out=filename_2022-01-27 replace
sheet="sheetname";
MPRINT(IMPORT):   namerow=7;
MPRINT(IMPORT):   startrow=10;
MPRINT(IMPORT):   *Endrow=934 (the end rows are not the same for each table;
MPRINT(IMPORT):   getnames=yes;
MPRINT(IMPORT):   run;
NOTE: Line generated by the macro variable "T01".
1                filename_2022-01-27
                              ---
                              22
                              200
ERROR 22-322: Syntax error, expecting one of the following: ;, (, DATAFILE, DATATABLE, DBMS, DEBUG,
              FILE, OUT, REPLACE, TABLE, _DEBUG_.

ERROR 200-322: The symbol is not recognized and will be ignored.

16   %import (filename_2022-01-31);
MPRINT(IMPORT):   FILENAME REFFILE
"filepath\filename_2022-01-31.xls";


NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

NOTE: The SAS System stopped processing this step because of errors.
MPRINT(IMPORT):   proc import datafile=refile dbms=xls out=filename_2022-01-31 replace
sheet="sheetname";
MPRINT(IMPORT):   namerow=7;
MPRINT(IMPORT):   startrow=10;
MPRINT(IMPORT):   *Endrow=934 (the end rows are not the same for each table;
MPRINT(IMPORT):   getnames=yes;
MPRINT(IMPORT):   run;
NOTE: Line generated by the macro variable "T01".
1                filename_2022-01-31
                              ---
                              22
                              200
ERROR 22-322: Syntax error, expecting one of the following: ;, (, DATAFILE, DATATABLE, DBMS, DEBUG,
              FILE, OUT, REPLACE, TABLE, _DEBUG_.

ERROR 200-322: The symbol is not recognized and will be ignored.

17   /*etc.*/
18   /*the table name with -01-27, etc. that not work*/
19   run;&lt;/PRE&gt;&lt;P&gt;@&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 17:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794292#M32823</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-02-03T17:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794294#M32825</link>
      <description>&lt;P&gt;I think the &lt;A href="https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794281#M32816" target="_self"&gt;answer I gave above&lt;/A&gt; identifies the problem.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 17:25:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794294#M32825</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-02-03T17:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794297#M32827</link>
      <description>&lt;P&gt;Please put your code in code blocks.&lt;/P&gt;
&lt;P&gt;Try using COMPRESS() to remove the - and spaces from file names. You need to create valid data set names for the data sets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this doesn't work, make sure to post the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen;
%macro import(T01);

FILENAME REFFILE "filepath\&amp;amp;T01..xls";

proc import datafile=refile dbms=xls out=%sysfunc(compress(&amp;amp;T01. , "- ") replace;
sheet="sheetname";
namerow=7;
startrow=10;
*Endrow=934 (the end rows are not the same for each table how could I fix that;
getnames=yes;
run;
%mend import;

%import (filename_2022-01-27);
%import (filename_2022-01-31);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/413003"&gt;@Didi_b&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I would like to import multiple Excel file into SAS using macro. My programm didn't work because my files names are ending with dates. Also my line endrow is different for each excel file. I would like to get some help to succeed please. Excel file name are the same in different excel file, the difference is on date. The sheet name in each Excel file are the same too as the rest except the Endrow. I can't change the Excel files name because there are a lot of them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here my program :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro import(R01);&lt;BR /&gt;FILENAME REFFILE "filepath\&amp;amp;T01..xls";&lt;/P&gt;
&lt;P&gt;proc import datafile=refile dbms=xls out=&amp;amp;T01. replace;&lt;BR /&gt;sheet="sheetname";&lt;BR /&gt;namerow=7;&lt;BR /&gt;startrow=10;&lt;BR /&gt;*Endrow=934 (the end rows are not the same for each table how could I fix that;&lt;BR /&gt;getnames=yes;&lt;BR /&gt;run;&lt;BR /&gt;%mend import;&lt;/P&gt;
&lt;P&gt;%import (filename_2022-01-27);&lt;BR /&gt;%import (filename_2022-01-31);&lt;BR /&gt;/*etc.*/&lt;BR /&gt;/*the table name with -01-27, etc. not working*/&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 17:29:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794297#M32827</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-03T17:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794299#M32828</link>
      <description>&lt;P&gt;Sure it is a xls files&lt;BR /&gt;I copy past the file name.&lt;/P&gt;&lt;P&gt;When I proc import one file whitout macro it works. Since I have a lot of them I need to use macro.&lt;/P&gt;&lt;P&gt;Thanks I'll look for what you suggested in forum&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 17:33:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794299#M32828</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-02-03T17:33:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794300#M32829</link>
      <description>&lt;P&gt;Yes it is a legal SAS code. I just replace the sensitive name with filename that's it.&lt;/P&gt;&lt;P&gt;I didn't touch the rest. When I proc import one Excel file without the macro it works fine. But I need the macro since I have a lot of Excel Files.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 17:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794300#M32829</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-02-03T17:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794302#M32830</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/413003"&gt;@Didi_b&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes it is a legal SAS code.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No it is not legal SAS code. Can data set names have hyphens in it?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 17:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794302#M32830</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-02-03T17:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794303#M32831</link>
      <description>Depends on validvarname option?</description>
      <pubDate>Thu, 03 Feb 2022 17:40:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794303#M32831</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-03T17:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794305#M32832</link>
      <description>&lt;P&gt;Your dates contain hyphens, which are not allowed in dataset names. Remove them for the dataset name.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 17:43:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794305#M32832</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-03T17:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794308#M32833</link>
      <description>&lt;P&gt;Even with validmemname=extend, one would then need name literals.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 17:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794308#M32833</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-03T17:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794312#M32834</link>
      <description>True...</description>
      <pubDate>Thu, 03 Feb 2022 18:00:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794312#M32834</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-03T18:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794315#M32835</link>
      <description>&lt;P&gt;You can add more parameters to the macro to give the user more control.&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import(filename,member);
%if 0=%length(&amp;amp;member) %then %let member=%sysfunc(compress(&amp;amp;filename,. -));

proc import
  datafile="filepath\&amp;amp;filename..xls"
  dbms=xls 
  out=&amp;amp;member. replace
;
  sheet="sheetname";
  namerow=7;
  startrow=10;
  getnames=yes;
run;
%mend import;

%import(filename_2022-01-27);
%import(filename_2022-01-31,filename_2022_01_31);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As to your other question:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;*Endrow=934 (the end rows are not the same for each table how could I fix that;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You need to explain more what that means.&amp;nbsp; Is the problem that there are "footers" in the Excel sheets that are not data? What problems do they cause?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are they easy to detect and delete after the data is imported?&amp;nbsp; In which case just add a where= dataset option to the OUT= dataset to eliminate those observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or does including them cause changes to the data you do want?&amp;nbsp; In that case read the file twice. Check the first version and figure out what value to use for the ENDROW= statement and put it into a macro variable you can use to re-import the file with that setting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 18:15:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794315#M32835</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-02-03T18:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794320#M32836</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/413003"&gt;@Didi_b&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Sure it is a xls files&lt;BR /&gt;I copy past the file name.&lt;/P&gt;
&lt;P&gt;When I proc import one file whitout macro it works. Since I have a lot of them I need to use macro.&lt;/P&gt;
&lt;P&gt;Thanks I'll look for what you suggested in forum&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;By default SAS will not allow data sets to have - characters in the names. SAS data set names start with _ or a letter and contain _, letters and digits only by default. So either replace the - with _ characters or live with using name literals setting the OPTION VALIDMENAME=EXTEND; AND then having to write "Something-dash"N name literals to reference data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the OUT= is attempting to create an invalid SAS data set name.&lt;/P&gt;
&lt;PRE&gt;proc import datafile=refile dbms=xls out=&amp;amp;T01. replace;&lt;/PRE&gt;
&lt;P&gt;Strongly suggest replacing the - characters with _.&lt;/P&gt;
&lt;P&gt;It takes ONE line of code to replace the - with _ as shown below:&lt;/P&gt;
&lt;PRE&gt;%macro dummy (to);
%let to = %sysfunc(translate(&amp;amp;to.,_,-));
%put to is now: &amp;amp;to.;
%mend;

%dummy(filename_2021-01-23)&lt;/PRE&gt;
&lt;P&gt;Which will show in the log:&lt;/P&gt;
&lt;PRE&gt;to is now: filename_2021_01_23
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 18:36:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794320#M32836</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-03T18:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794337#M32838</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;/**here my separate proc import that works fine*/

proc import datafile="Z:\x\_Stat\T01\Call_Global_2022-01-27.xls" dbms=xls out=table1 replace;
sheet="FileGroup";
namerow=7;
startrow=10;
Endrow=943;
getnames=yes;
run;

proc import datafile="Z:\x\_Stat\T01\Call_Global_2022-01-31.xls" dbms=xls out=table2 replace;
sheet="FileGroup";
namerow=7;
startrow=10;
*Endrow=958;
getnames=yes;
run;

/****Here my macro import that doesn't work beacuse of the date in file name with '-'**/

%macro import(T01);

FILENAME REFFILE "Z:\x\_Stat\T01\&amp;amp;T01..xls";

PROC IMPORT DATAFILE=REFFILE DBMS=XLS OUT=&amp;amp;T01. REPLACE; 
GETNAMES=YES;
RUN;
%mend import;

%import (Call_Global_2022-01-27);
%import (Call_Global_2022-01-27);
/*etc.*/
run;
/********************/

/**Reeza, Here your solution I applied** I add one parenthes that was missing and the run statement*/

options mprint symbolgen;
%macro import(T01);

FILENAME REFFILE "Z:\x\_Stat\&amp;amp;T01..xls";

proc import datafile="Z:\x\_Stat\&amp;amp;T01..xls" dbms=xls out=%sysfunc(compress(&amp;amp;T01. , "- ")) replace;
sheet="FileGroup";
namerow=7;
startrow=10;
getnames=yes;
run;
%mend import;

%import (filename_2022-01-27);
%import (filename_2022-01-31);
run;

/*Here the log result when I apply your solution*/

1    options mprint symbolgen;
2    %macro import(T01);
3
4    FILENAME REFFILE "Z:\x\_Stat\&amp;amp;T01..xls";
5
6    proc import datafile="Z:\x\_Stat\&amp;amp;T01..xls" dbms=xls out=%sysfunc(compress(&amp;amp;T01. , "-
6  !  ")) replace;
7    sheet="FileGroup";
8    namerow=7;
9    startrow=10;
10   getnames=yes;
11   run;
12   %mend import;
13
14   %import (filename_2022-01-27);
SYMBOLGEN:  Macro variable T01 resolves to filename_2022-01-27
MPRINT(IMPORT):   FILENAME REFFILE "Z:\x\_Stat\filename_2022-01-27.xls";
SYMBOLGEN:  Macro variable T01 resolves to filename_2022-01-27
SYMBOLGEN:  Macro variable T01 resolves to filename_2022-01-27
MPRINT(IMPORT):   proc import datafile="Z:\x\_Stat\filename_2022-01-27.xls" dbms=xls
out=filename_20220127 replace;
MPRINT(IMPORT):   RXCL;
MPRINT(IMPORT):   sheet="FileGroup";
MPRINT(IMPORT):   namerow=7;
MPRINT(IMPORT):   startrow=10;
MPRINT(IMPORT):   getnames=yes;
MPRINT(IMPORT):   run;

ERROR: Physical file does not exist, Z:\x\_Stat\filename_2022-01-27.xls.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.08 seconds
      cpu time            0.03 seconds

15   %import (filename_2022-01-31);
SYMBOLGEN:  Macro variable T01 resolves to filename_2022-01-31
MPRINT(IMPORT):   FILENAME REFFILE "Z:\x\_Stat\filename_2022-01-31.xls";

SYMBOLGEN:  Macro variable T01 resolves to filename_2022-01-31
SYMBOLGEN:  Macro variable T01 resolves to filename_2022-01-31
MPRINT(IMPORT):   proc import datafile="Z:\x\_Stat\filename_2022-01-31.xls" dbms=xls
out=filename_20220131 replace;
MPRINT(IMPORT):   RXCL;
MPRINT(IMPORT):   sheet="FileGroup";
MPRINT(IMPORT):   namerow=7;
MPRINT(IMPORT):   startrow=10;
MPRINT(IMPORT):   getnames=yes;
MPRINT(IMPORT):   run;

ERROR: Physical file does not exist, Z:\x\_Stat\filename_2022-01-31.xls.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

16   run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;I was making a copy of two Excel file to show you so you could help me better (in file path I put x in place of real name because I can't share it). I hope you could help with my new post. Thanks for taking the time to help me. I really appreciate it.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 19:46:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794337#M32838</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-02-03T19:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro in proc import with file name ending with a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794338#M32839</link>
      <description>&lt;P&gt;So in your example code you have the OUT=table1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However in your original macro you have OUT=filename_2022-01-31&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I added the COMPRESS function to fix that, which it seems to have done but you know have a different error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ERROR: Physical file does not exist, &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;Z:\x\_Stat\filename_2022-01-31.xls.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Looking at your code that works your path was along the lines of :&lt;/P&gt;
&lt;PRE&gt;"Z:\x\_Stat\T01\&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Call_Global_&lt;/FONT&gt;&lt;/STRONG&gt;2022-01-31.xls&lt;/PRE&gt;
&lt;P&gt;You're missing the CALL_GLOBAL part of the file name it seems.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fix your path to the files in the macro and it should work fine.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 19:54:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macro-in-proc-import-with-file-name-ending-with-a-date/m-p/794338#M32839</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-03T19:54:49Z</dc:date>
    </item>
  </channel>
</rss>

