<?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: How to replicate work for all sheets in Excel in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709122#M217988</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;, the log is as below, any abnormal things so far I should check ?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='replicate code for all sheets -included s34 _inc filenamer';
4          %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5          %LET _CLIENTPROJECTPATH='C:\Users\pnguyen\OneDrive - Massey University\SAS\29_Dec_redo_all.egp';
6          %LET _CLIENTPROJECTPATHHOST='IT082760';
7          %LET _CLIENTPROJECTNAME='29_Dec_redo_all.egp';
8          %LET _SASPROGRAMFILE='';
9          %LET _SASPROGRAMFILEHOST='';
10         
11         ODS _ALL_ CLOSE;
12         OPTIONS DEV=SVG;
13         GOPTIONS XPIXELS=0 YPIXELS=0;
14         %macro HTML5AccessibleGraphSupported;
15             %if %_SAS_VERCOMP_FV(9,4,4, 0,0,0) &amp;gt;= 0 %then ACCESSIBLE_GRAPH;
16         %mend;
17         FILENAME EGHTML TEMP;
18         ODS HTML5(ID=EGHTML) FILE=EGHTML
19             OPTIONS(BITMAP_MODE='INLINE')
20             %HTML5AccessibleGraphSupported
21             ENCODING='utf-8'
22             STYLE=HtmlBlue
23             NOGTITLE
24             NOGFOOTNOTE
25             GPATH=&amp;amp;sasworklocation
26         ;
NOTE: Writing HTML5(EGHTML) Body file: EGHTML
27         
28         options compress=yes reuse=yes;
29         
30         %macro ImportAndTranspose(
31               File=
32               , StartSheet=
33               , EndSheet=
34            );
35         
36            %local i;
37         
38            %do i = &amp;amp;StartSheet. %to &amp;amp;EndSheet.;
39         
40             %if &amp;amp;i=1 %then %do;
41         	
42             proc import datafile= "&amp;amp;File."
43                           out= sheet1
44                           dbms= xlsx
45                           replace;
46                   range= "Sheet1$A:X";
47                   getnames= yes;
48               run;
49         
50               proc sort data= sheet1;
51               by Type;
52               run;
53         	%end;
54         
55         	  %else %if &amp;amp;i= &amp;amp;EndSheet. %then %do;
56               proc import datafile= "&amp;amp;File."
57                           out= sheet&amp;amp;i.
2                                                          The SAS System                              14:42 Sunday, January 3, 2021

58                           dbms= xlsx
59                           replace;
60                   range= "Sheet&amp;amp;i.$A:AG";
61                   getnames= yes;
62               run;
63         
64               proc sort data= sheet&amp;amp;i.;
65               by Type;
66               run;
67         
68               proc transpose data= sheet&amp;amp;i.
69                     out= sheet&amp;amp;i._out(rename=(COL1=s&amp;amp;i. _NAME_=Year) drop=_label_);
70                  by Type;
71                  VAR '1988'N - '2019'N;
72               run;
73         	  proc print data=sheet&amp;amp;i._out;
74         	  run;
75         
76         	  data sheet&amp;amp;i._outx;
77         	  set sheet&amp;amp;i._out;
78               if s&amp;amp;i. in: ('NA', '$$') then s&amp;amp;i. =".";
79         	  run;
80         
81         	  %end;
82         
83         
84             %else %if (&amp;amp;i ne 1) and (&amp;amp;i ne Endsheet.) %then %do;
85               proc import datafile= "&amp;amp;File."
86                           out= sheet&amp;amp;i.
87                           dbms= xlsx
88                           replace;
89                   range= "Sheet&amp;amp;i.$A:AG";
90                   getnames= yes;
91               run;
92         
93               proc sort data= sheet&amp;amp;i.;
94               by Type;
95               run;
96         
97               proc transpose data= sheet&amp;amp;i.
98                     out= sheet&amp;amp;i._out(rename=(COL1=s&amp;amp;i. _NAME_=Year) drop=_label_);
99                  by Type;
100                 VAR '1988'N - '2019'N;
101              run;
102        	  proc print data=sheet&amp;amp;i._out;
103        	  run;
104        
105              DATA sheet&amp;amp;i._outx;
106              set sheet&amp;amp;i._out;
107        
108              if s&amp;amp;i. not in: ('NA', '$$') then s&amp;amp;i.2=input(s&amp;amp;i., 32.);
109        	  drop s&amp;amp;i.;
110              run;
111        	  %end;
112        
113        
114        
115           %end;
3                                                          The SAS System                              14:42 Sunday, January 3, 2021

116        
117        %mend;
118        
119        *Replicate all file in one folder;
120           data _null_;
121        length fref $8 fname $200;
122        did = filename(fref,'C:\Users\pnguyen\Desktop\New folder');
123        did = dopen(fref);
124        do i = 1 to dnum(did);
125          fname = dread(did,i);
126          cmd=cats('%ImportAndTranspose(File=',
127              strip(fname),',startsheet=1,endsheet=34);');
128          put cmd = ;
129        end;
130        did = dclose(did);
131        did = filename(fref);
132        keep fname;
133        run;

cmd=%ImportAndTranspose(File=Argentina_.xlsx,startsheet=1,endsheet=34);
cmd=%ImportAndTranspose(File=Bulgaria_.xlsx,startsheet=1,endsheet=34);
cmd=%ImportAndTranspose(File=Colombia_.xlsx,startsheet=1,endsheet=34);
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

134        
135        %LET _CLIENTTASKLABEL=;
136        %LET _CLIENTPROCESSFLOWNAME=;
137        %LET _CLIENTPROJECTPATH=;
138        %LET _CLIENTPROJECTPATHHOST=;
139        %LET _CLIENTPROJECTNAME=;
140        %LET _SASPROGRAMFILE=;
141        %LET _SASPROGRAMFILEHOST=;
142        
143        ;*';*";*/;quit;run;
144        ODS _ALL_ CLOSE;
145        
146        
147        QUIT; RUN;
148     &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Many thanks!&lt;/P&gt;
&lt;DIV id="eJOY__extension_root" class="eJOY__extension_root_class" style="all: unset;"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Sun, 03 Jan 2021 03:57:23 GMT</pubDate>
    <dc:creator>Phil_NZ</dc:creator>
    <dc:date>2021-01-03T03:57:23Z</dc:date>
    <item>
      <title>How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708472#M217728</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;Today I deal with replicating the same code for all sheets in Excel, &lt;STRONG&gt;just change the number of sheets&lt;/STRONG&gt;, For example, the codes for sheets i (i=1,33) are the same.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC IMPORT OUT= sheet2 DATAFILE= "C:\Users\pnguyen\Desktop\Argentina - delete.xlsm" 
            DBMS=xlsx REPLACE;
	 RANGE="Sheet2$A:AG";
     GETNAMES=YES;
RUN;

proc sort data=sheet2;
by Type;
run;

proc transpose data=sheet2 out=sheet2_out(rename=(COL1=sheet2 _NAME_=Year) drop=_label_);
   by Type;
   VAR '1988'N - '2019'N;
	transposing;
run;

PROC IMPORT OUT= sheet3 DATAFILE= "C:\Users\pnguyen\Desktop\Argentina - delete.xlsm" 
            DBMS=xlsx REPLACE;
	 RANGE="Sheet3$A:AG";
     GETNAMES=YES;
RUN;

proc sort data=sheet3;
by Type;
run;

proc transpose data=sheet3 out=sheet3_out(rename=(COL1=sheet3 _NAME_=Year) drop=_label_);
   by Type;
   VAR '1988'N - '2019'N;
	transposing;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;1. Can you please suggest to me any way to wrap up or simplify the code rather than wrote such a group of code for 33 sheets in one excel file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. And a further question is: I have 65 files,each file contains 33 sheets like that, and the code for each file are totally the same, is there any way to work with 65 files by using SAS code rather than deal with each file manually?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks and warmest regards.&lt;/P&gt;
&lt;DIV id="eJOY__extension_root" class="eJOY__extension_root_class" style="all: unset;"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Mon, 28 Dec 2020 20:30:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708472#M217728</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2020-12-28T20:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708475#M217730</link>
      <description>&lt;P&gt;Is it that PROC EXPORT and PROC IMPORT are necessary.&amp;nbsp; Could you use LIBNAME with XLSX engine to import and ODS EXCEL with PROC PRINT to export?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Dec 2020 21:02:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708475#M217730</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2020-12-28T21:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708492#M217736</link>
      <description>Hi PhilC, I just used the Proc import, not export,&lt;BR /&gt;But thank you for your suggestion, I think they are interchangeably used.&lt;BR /&gt;I mean, if I use LIBNAME with XLSX, could I make my above code shorter?&lt;BR /&gt;&lt;BR /&gt;Many thanks and cheers.&lt;BR /&gt;</description>
      <pubDate>Tue, 29 Dec 2020 00:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708492#M217736</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2020-12-29T00:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708493#M217737</link>
      <description>&lt;P&gt;If you can change from xlsm to xlsx, try next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname myxl xlsx "C:\Users\pnguyen\Desktop\Argentina - delete.xlsm";

%macro xlread;
      %do i=1 %to 33;
          data sheet&amp;amp;i;
             set myxl.sheet&amp;amp;i;
          run;
          proc sort data=sheet&amp;amp;i; by type; run;
          proc transpose data=sheet&amp;amp;i  out==sheet&amp;amp;i._out
                       (rename=(COL1=sheet&amp;amp;i. _NAME_=Year)  drop=_label_);
               by type;
               VAR '1988'N - '2019'N;
	       transposing;
           run;
    %end;
%mend xlread;
%xlread;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Dec 2020 01:09:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708493#M217737</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-12-29T01:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708503#M217745</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your insightful reply, I tried to change the file's form from xlsm to xlsx already, However, when I try to run the code, there are still some errors happening&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname myxl xlsx "C:\Users\pnguyen\Desktop\Argentina.xlsx";

%macro xlread;
      %do i=2 %to 33;
          data sheet&amp;amp;i;
             set myxl.sheet&amp;amp;i;
          run;
          proc sort data=sheet&amp;amp;i; by Type; run;
          proc transpose data=s&amp;amp;i  out==sheet&amp;amp;i._out
                       (rename=(COL1=sheet&amp;amp;i. _NAME_=Year)  drop=_label_);
               by type;
               VAR '1988'N - '2019'N;
	       transposing;
           run;
		   DATA sheet2_outx;
               set sheet2_out;
               s&amp;amp;i2=input(s2,?? 32.);
           run;
    %end;
%mend xlread;
%xlread;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the result comes out with a couple of error as below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1                                                          The SAS System                           08:27 Tuesday, December 29, 2020

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='Loop 33 files';
4          %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5          %LET _CLIENTPROJECTPATH='C:\Users\pnguyen\OneDrive - Massey University\SAS\29_Dec_redo_all.egp';
6          %LET _CLIENTPROJECTPATHHOST='IT082760';
7          %LET _CLIENTPROJECTNAME='29_Dec_redo_all.egp';
8          %LET _SASPROGRAMFILE='';
9          %LET _SASPROGRAMFILEHOST='';
10         
11         ODS _ALL_ CLOSE;
12         OPTIONS DEV=SVG;
13         GOPTIONS XPIXELS=0 YPIXELS=0;
14         %macro HTML5AccessibleGraphSupported;
15             %if %_SAS_VERCOMP_FV(9,4,4, 0,0,0) &amp;gt;= 0 %then ACCESSIBLE_GRAPH;
16         %mend;
17         FILENAME EGHTML TEMP;
18         ODS HTML5(ID=EGHTML) FILE=EGHTML
19             OPTIONS(BITMAP_MODE='INLINE')
20             %HTML5AccessibleGraphSupported
21             ENCODING='utf-8'
22             STYLE=HtmlBlue
23             NOGTITLE
24             NOGFOOTNOTE
25             GPATH=&amp;amp;sasworklocation
26         ;
NOTE: Writing HTML5(EGHTML) Body file: EGHTML
27         
28         
29         libname myxl xlsx "C:\Users\pnguyen\Desktop\Argentina.xlsx";
NOTE: Libref MYXL was successfully assigned as follows: 
      Engine:        XLSX 
      Physical Name: C:\Users\pnguyen\Desktop\Argentina.xlsx
30         
31         %macro xlread;
32               %do i=2 %to 33;
33                   data sheet&amp;amp;i;
34                      set myxl.sheet&amp;amp;i;
35                   run;
36                   proc sort data=sheet&amp;amp;i; by Type; run;
37                   proc transpose data=s&amp;amp;i  out==sheet&amp;amp;i._out
38                                (rename=(COL1=sheet&amp;amp;i. _NAME_=Year)  drop=_label_);
39                        by type;
40                        VAR '1988'N - '2019'N;
41         	       transposing;
42                    run;
43         		   DATA sheet2_outx;
44                        set sheet2_out;
45                        s&amp;amp;i2=input(s2,?? 32.);
46                    run;
47             %end;
48         %mend xlread;
49         %xlread;

NOTE: The import data set has 453 observations and 36 variables.
NOTE: There were 453 observations read from the data set MYXL.sheet2.
NOTE: The data set WORK.SHEET2 has 453 observations and 36 variables.
NOTE: Compressing data set WORK.SHEET2 decreased size by 66.67 percent. 
2                                                          The SAS System                           08:27 Tuesday, December 29, 2020

      Compressed is 1 pages; un-compressed would require 3 pages.
NOTE: DATA statement used (Total process time):
      real time           0.07 seconds
      cpu time            0.06 seconds
      


NOTE: There were 453 observations read from the data set WORK.SHEET2.
NOTE: The data set WORK.SHEET2 has 453 observations and 36 variables.
NOTE: Compressing data set WORK.SHEET2 decreased size by 66.67 percent. 
      Compressed is 1 pages; un-compressed would require 3 pages.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      

&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ERROR: File WORK.S2.DATA does not exist.&lt;/STRONG&gt;&lt;/FONT&gt;
&lt;FONT color="#FF0000"&gt;22: LINE and COLUMN cannot be determined.&lt;/FONT&gt;
NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
&lt;FONT color="#FF0000"&gt;ERROR 22-322: Expecting a name.  
76: LINE and COLUMN cannot be determined.&lt;/FONT&gt;
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
&lt;FONT color="#FF0000"&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/FONT&gt;
NOTE: Line generated by the invoked macro "XLREAD".
49                         by type;                VAR '1988'N - '2019'N;         transposing;            run;
                                                                                  ___________
                                                                                  1

&lt;FONT color="#008000"&gt;WARNING 1-322: Assuming the symbol TRANSPOSE was misspelled as transposing.&lt;/FONT&gt;

NOTE: The SAS System stopped processing this step because of errors.
&lt;FONT color="#008000"&gt;WARNING: The data set WORK.DATA161 may be incomplete.  When this step was stopped there were 0 observations and 0 variables.&lt;/FONT&gt;
NOTE: Compression was disabled for data set WORK.DATA161 because compression overhead would increase the size of the data set.
NOTE: PROCEDURE TRANSPOSE used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      


NOTE: Line generated by the invoked macro "XLREAD".
49                                                                                                                  DATA sheet2_outx
49       ! ;                set sheet2_out;                s&amp;amp;i2=input(s2,?? 32.);            run;
                                                           _
                                                           180
&lt;FONT color="#008000"&gt;WARNING: Apparent symbolic reference I2 not resolved.&lt;/FONT&gt;

&lt;FONT color="#FF0000"&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/FONT&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can you please help me to sort it out?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks and regards.&lt;/P&gt;
&lt;DIV id="eJOY__extension_root" class="eJOY__extension_root_class" style="all: unset;"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 29 Dec 2020 03:55:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708503#M217745</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2020-12-29T03:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708506#M217747</link>
      <description>I mean, how to deal with the error :"22: LINE and COLUMN cannot be determined."&lt;BR /&gt;&lt;BR /&gt;Thank you!</description>
      <pubDate>Tue, 29 Dec 2020 04:07:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708506#M217747</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2020-12-29T04:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708508#M217749</link>
      <description>&lt;P&gt;And how can I import the data range as the first code in this macro code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	 RANGE="Sheet2$A:AG";
     GETNAMES=YES;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;DIV id="eJOY__extension_root" class="eJOY__extension_root_class" style="all: unset;"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 29 Dec 2020 04:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708508#M217749</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2020-12-29T04:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708515#M217752</link>
      <description>&lt;P&gt;1) I noticed that you added a step to the macro updating &lt;STRONG&gt;SHEET2&lt;/STRONG&gt;_OUT dataset,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;while the macro creates &lt;STRONG&gt;sheet&amp;amp;i.&lt;/STRONG&gt;_out dataset. Was it intentional ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;The code &lt;STRONG&gt;s&amp;amp;i2&lt;/STRONG&gt;&amp;nbsp; will result, for any&amp;nbsp;&lt;STRONG&gt;i&lt;/STRONG&gt; with an unresolved macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;In order to resolve for&amp;nbsp; &lt;STRONG&gt;i=2 &lt;/STRONG&gt;as&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;s22 &lt;/STRONG&gt;or&amp;nbsp;&amp;nbsp;for &lt;STRONG&gt;i=3&amp;nbsp;&lt;/STRONG&gt;as&amp;nbsp;&lt;STRONG&gt;s32&lt;/STRONG&gt;, code it as&amp;nbsp;&lt;STRONG&gt;s&amp;amp;i.2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;The added dot defines the end of macro variable name.&lt;/P&gt;
&lt;P&gt;2) According to next log messages:&lt;/P&gt;
&lt;PRE&gt;22: LINE and COLUMN cannot be determined.
NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; and in order to debug the macro precede the macro execution (%xlread;) with&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; the next line:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options spool mprint symbolgen;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;3) To relate to a range of a sheet you can &lt;STRONG&gt;drop&lt;/STRONG&gt; the excess columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2020 07:37:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708515#M217752</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-12-29T07:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708518#M217753</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212695"&gt;@Phil_NZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;Today I deal with replicating the same code for all sheets in Excel, &lt;STRONG&gt;just change the number of sheets&lt;/STRONG&gt;, For example, the codes for sheets i (i=1,33) are the same.&lt;/P&gt;
&lt;P&gt;[...]&lt;/P&gt;
&lt;P&gt;1. Can you please suggest to me any way to wrap up or simplify the code rather than wrote such a group of code for 33 sheets in one excel file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. And a further question is: I have 65 files,each file contains 33 sheets like that, and the code for each file are totally the same, is there any way to work with 65 files by using SAS code rather than deal with each file manually?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks and warmest regards.&lt;/P&gt;
&lt;DIV id="eJOY__extension_root" class="eJOY__extension_root_class" style="all: unset;"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You could wrap the three steps in a macro-loop (code is untested):&lt;/P&gt;
&lt;PRE&gt;%macro ImportAndTranspose(
      File=
      , StartSheet=
      , EndSheet=
   );
   
   %local i;
   
   %do i = &amp;amp;StartSheet. %to &amp;amp;EndSheet.;
      proc import datafile= "&amp;amp;File." 
                  out= sheet&amp;amp;i.
                  dbms= xlsx 
                  replace;
          range= "Sheet&amp;amp;i.$A:AG";
          getnames= yes;
      run;
      
      proc sort data= sheet&amp;amp;i.;
      by Type;
      run;

      proc transpose data= sheet&amp;amp;i. 
            out= sheet&amp;amp;i._out(rename=(COL1=sheet&amp;amp;i. _NAME_=Year) drop=_label_);
         by Type;
         VAR '1988'N - '2019'N;
      run;
   %end;
%mend;

%macro ImportAndTranspose(
      File= C:\Users\pnguyen\Desktop\Argentina - delete.xlsm
      , StartSheet= 1
      , EndSheet= 33
   );&lt;/PRE&gt;
&lt;P&gt;The answer of the second question depends on the way the files are stored. If they are in one directory, you could use a data step to get the filenames and use call execute to call the macro for each file. Or you could add another macro-loop to read the filenames. If files exist in the directory that must not be processed, you need rules to get the right files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2020 06:47:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708518#M217753</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-12-29T06:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708530#M217763</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help. I understand fully your code. However, when I try to run it, it does not work&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ImportAndTranspose(
      File=
      , StartSheet=
      , EndSheet=
   );
   
   %local i;
   
   %do i = &amp;amp;StartSheet. %to &amp;amp;EndSheet.;
      proc import datafile= "&amp;amp;File." 
                  out= sheet&amp;amp;i.
                  dbms= xlsx 
                  replace;
          range= "Sheet&amp;amp;i.$A:AG";
          getnames= yes;
      run;
      
      proc sort data= sheet&amp;amp;i.;
      by Type;
      run;

      proc transpose data= sheet&amp;amp;i. 
            out= sheet&amp;amp;i._out(rename=(COL1=sheet&amp;amp;i. _NAME_=Year) drop=_label_);
         by Type;
         VAR '1988'N - '2019'N;
      run;
	  proc print data=sheet&amp;amp;i._out;
	  run;
   %end;
   
%mend ImportAndTranspose;

%ImportAndTranspose(
      File= C:\Users\pnguyen\Desktop\Argentina.xlsx
      , StartSheet= 2
      , EndSheet= 5)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;I also attach the excel file here, can you please have a look?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Regarding your further question, all the files are in one folder, every file is a country. Can you give me a suggestion about macro-loop to read the file names (for all countries) in this folder?&lt;/P&gt;
&lt;P&gt;Many thanks and best regards.&lt;/P&gt;
&lt;DIV id="eJOY__extension_root" class="eJOY__extension_root_class" style="all: unset;"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 29 Dec 2020 08:44:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708530#M217763</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2020-12-29T08:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708535#M217766</link>
      <description>&lt;P&gt;1) Saying "&lt;SPAN&gt;when I try to run it, it does not work" it is not enough information.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; You should either explain what you got or post the log.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; I suspect that you miss a semicolon closing the macro execution ?!&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%ImportAndTranspose(
      File= C:\Users\pnguyen\Desktop\Argentina.xlsx
      , StartSheet= 2
      , EndSheet= 5);    /* semicolon added */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;if this is not the case run with a preceding &lt;STRONG&gt;options mprint symbolgen;&lt;/STRONG&gt;&amp;nbsp;and post the log.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2) The code&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;posted tries to keep your original code converting it to a macro&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;program and using xlsx instead xlsm format/engine.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2020 09:05:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708535#M217766</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-12-29T09:05:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709058#M217945</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp; for your insightful idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now I have the code for replicating work for all sheet in one file, and I also get the code for retrieving all file name in one folder, can you please give me a hint to run do-loop or else to replicate the given code to all files in this folder? I mean, running the macro "ImportandTranspose" for sheet 1 to 34 of all files in the "NewFolder" folder.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ImportAndTranspose(
      File=
      , StartSheet=
      , EndSheet=
   );
   
   %local i;
   
   %do i = &amp;amp;StartSheet. %to &amp;amp;EndSheet.;

    %if &amp;amp;i=1 %then %do;
	
    proc import datafile= "&amp;amp;File." 
                  out= sheet1
                  dbms= xlsx 
                  replace;
          range= "Sheet1$A:X";
          getnames= yes;
      run;
      
      proc sort data= sheet1;
      by Type;
      run;
	%end;

	  %else %if &amp;amp;i= &amp;amp;EndSheet. %then %do;
      proc import datafile= "&amp;amp;File." 
                  out= sheet&amp;amp;i.
                  dbms= xlsx 
                  replace;
          range= "Sheet&amp;amp;i.$A:AG";
          getnames= yes;
      run;
      
      proc sort data= sheet&amp;amp;i.;
      by Type;
      run;

      proc transpose data= sheet&amp;amp;i. 
            out= sheet&amp;amp;i._out(rename=(COL1=s&amp;amp;i. _NAME_=Year) drop=_label_);
         by Type;
         VAR '1988'N - '2019'N;
      run;
	  proc print data=sheet&amp;amp;i._out;
	  run;

	  data sheet&amp;amp;i._outx;
	  set sheet&amp;amp;i._out;
      if s&amp;amp;i. in: ('NA', '$$') then s&amp;amp;i. =".";
	  run;

	  %end;
    
   
    %else %if (&amp;amp;i ne 1) and (&amp;amp;i ne Endsheet.) %then %do;
      proc import datafile= "&amp;amp;File." 
                  out= sheet&amp;amp;i.
                  dbms= xlsx 
                  replace;
          range= "Sheet&amp;amp;i.$A:AG";
          getnames= yes;
      run;
      
      proc sort data= sheet&amp;amp;i.;
      by Type;
      run;

      proc transpose data= sheet&amp;amp;i. 
            out= sheet&amp;amp;i._out(rename=(COL1=s&amp;amp;i. _NAME_=Year) drop=_label_);
         by Type;
         VAR '1988'N - '2019'N;
      run;
	  proc print data=sheet&amp;amp;i._out;
	  run;

      DATA sheet&amp;amp;i._outx;
      set sheet&amp;amp;i._out;

      if s&amp;amp;i. not in: ('NA', '$$') then s&amp;amp;i.2=input(s&amp;amp;i., 32.);
	  drop s&amp;amp;i.;
      run;
	  %end;



   %end;
   
%mend;

*Get filename;
   data filenames;
length fref $8 fname $200;
did = filename(fref,'C:\Users\pnguyen\Desktop\New folder');
did = dopen(fref);
do i = 1 to dnum(did);
  fname = dread(did,i);
  output;
end;
did = dclose(did);
did = filename(fref);
keep fname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Many thanks and warmest regards!&lt;/P&gt;
&lt;DIV id="eJOY__extension_root" class="eJOY__extension_root_class" style="all: unset;"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sat, 02 Jan 2021 09:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709058#M217945</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-02T09:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709060#M217947</link>
      <description>&lt;P&gt;To run macro %&lt;STRONG&gt;ImportAndTranspose&lt;/STRONG&gt; for each &lt;STRONG&gt;fname&lt;/STRONG&gt; in &lt;STRONG&gt;filenames&lt;/STRONG&gt; dataset,&lt;/P&gt;
&lt;P&gt;supposing all of them are xlsx format and all sheets are as expected, you can submit the macro within the same step creating the filenames dataset, either by using&amp;nbsp;&lt;STRONG&gt;call execute()&lt;/STRONG&gt; function or by creating a program file to be executed in next step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Option-1 - Get filenames and execute the macro */
data _null_;  /* instead filenames; */
	length fref $8 fname $200;
	did = filename(fref,'C:\Users\pnguyen\Desktop\New folder');
	did = dopen(fref);
	do i = 1 to dnum(did);
	   fname = dread(did,i);
	   /* output; &amp;lt;&amp;lt; to be replaced withe: */
	   cmd = catx(',', '%ImportAndTranspose(File=',
	         strip(fname),'startsheet=1,endsheet=34);');
	   call execute(cmd);
	end;
	did = dclose(did);
	did = filename(fref);
keep fname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Alternative way, enables check the generated program before execution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Option-2 - Get filenames and execute the macro */
filename program tmp 'tmp.sas';
data _null_;  /* instead filenames; */
	length fref $8 fname $200;
	did = filename(fref,'C:\Users\pnguyen\Desktop\New folder');
	did = dopen(fref);
	do i = 1 to dnum(did);
	   fname = dread(did,i);
	   /* output; &amp;lt;&amp;lt; to be replaced withe: */
	   cmd = catx(',', '%ImportAndTranspose(File=',
	         strip(fname),'startsheet=1,endsheet=34);');
	   file program;
	   put cmd;
	end;
	did = dclose(did);
	did = filename(fref);
keep fname;
run;
%include program;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Jan 2021 09:38:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709060#M217947</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-02T09:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709115#M217981</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;, many thanks for your idea and suggestion, I also have further question that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	did = dclose(did);
	did = filename(fref);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I know that "dclose" is to close the open directory and any open members. But I do not fully understand why we need&amp;nbsp; "did=filename(fref)"&amp;nbsp; at the end, what does it stand for?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And a question of curiousity, apart from using &lt;STRONG&gt;call execute (cmd)&lt;/STRONG&gt;, is there any way that can be used in this case instead?&lt;/P&gt;
&lt;P&gt;Many thanks!&lt;/P&gt;
&lt;DIV id="eJOY__extension_root" class="eJOY__extension_root_class" style="all: unset;"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sun, 03 Jan 2021 01:21:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709115#M217981</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-03T01:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709116#M217982</link>
      <description>&lt;P&gt;DCLOSE() closes the directory.&amp;nbsp; There are no members that were opened that need to close.&lt;/P&gt;
&lt;P&gt;FILENAME() without out any filename eliminates the fileref that was previously associated with the file (the fileref was actually associated with the directory in this case).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jan 2021 01:53:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709116#M217982</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-03T01:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709117#M217983</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;, another question is about the ERROR existing when running the macro called "All positional parameters must precede keyword parameters", could you please tell me how to sort it out?&lt;/P&gt;
&lt;P&gt;Here is my code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options compress=yes reuse=yes;

%macro ImportAndTranspose(
      File=
      , StartSheet=
      , EndSheet=
   );
   
   %local i;
   
   %do i = &amp;amp;StartSheet. %to &amp;amp;EndSheet.;

    %if &amp;amp;i=1 %then %do;
	
    proc import datafile= "&amp;amp;File." 
                  out= sheet1
                  dbms= xlsx 
                  replace;
          range= "Sheet1$A:X";
          getnames= yes;
      run;
      
      proc sort data= sheet1;
      by Type;
      run;
	%end;

	  %else %if &amp;amp;i= &amp;amp;EndSheet. %then %do;
      proc import datafile= "&amp;amp;File." 
                  out= sheet&amp;amp;i.
                  dbms= xlsx 
                  replace;
          range= "Sheet&amp;amp;i.$A:AG";
          getnames= yes;
      run;
      
      proc sort data= sheet&amp;amp;i.;
      by Type;
      run;

      proc transpose data= sheet&amp;amp;i. 
            out= sheet&amp;amp;i._out(rename=(COL1=s&amp;amp;i. _NAME_=Year) drop=_label_);
         by Type;
         VAR '1988'N - '2019'N;
      run;
	  proc print data=sheet&amp;amp;i._out;
	  run;

	  data sheet&amp;amp;i._outx;
	  set sheet&amp;amp;i._out;
      if s&amp;amp;i. in: ('NA', '$$') then s&amp;amp;i. =".";
	  run;

	  %end;
    
   
    %else %if (&amp;amp;i ne 1) and (&amp;amp;i ne Endsheet.) %then %do;
      proc import datafile= "&amp;amp;File." 
                  out= sheet&amp;amp;i.
                  dbms= xlsx 
                  replace;
          range= "Sheet&amp;amp;i.$A:AG";
          getnames= yes;
      run;
      
      proc sort data= sheet&amp;amp;i.;
      by Type;
      run;

      proc transpose data= sheet&amp;amp;i. 
            out= sheet&amp;amp;i._out(rename=(COL1=s&amp;amp;i. _NAME_=Year) drop=_label_);
         by Type;
         VAR '1988'N - '2019'N;
      run;
	  proc print data=sheet&amp;amp;i._out;
	  run;

      DATA sheet&amp;amp;i._outx;
      set sheet&amp;amp;i._out;

      if s&amp;amp;i. not in: ('NA', '$$') then s&amp;amp;i.2=input(s&amp;amp;i., 32.);
	  drop s&amp;amp;i.;
      run;
	  %end;



   %end;
   
%mend;

*Replicate all file in one folder;
   data _null_;
length fref $8 fname $200;
did = filename(fref,'C:\Users\pnguyen\Desktop\New folder');
did = dopen(fref);
do i = 1 to dnum(did);
  fname = dread(did,i);
  cmd=catx(',', '%ImportAndTranspose(File=',
      strip(fname), 'startsheet=1,endsheet=34);');
  call execute(cmd);
end;
did = dclose(did);
did = filename(fref);
keep fname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The log is as below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1                                                          The SAS System                              14:42 Sunday, January 3, 2021

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='replicate code for all sheets -included s34 _inc filenamer';
4          %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5          %LET _CLIENTPROJECTPATH='C:\Users\pnguyen\OneDrive - Massey University\SAS\29_Dec_redo_all.egp';
6          %LET _CLIENTPROJECTPATHHOST='IT082760';
7          %LET _CLIENTPROJECTNAME='29_Dec_redo_all.egp';
8          %LET _SASPROGRAMFILE='';
9          %LET _SASPROGRAMFILEHOST='';
10         
11         ODS _ALL_ CLOSE;
12         OPTIONS DEV=SVG;
13         GOPTIONS XPIXELS=0 YPIXELS=0;
14         %macro HTML5AccessibleGraphSupported;
15             %if %_SAS_VERCOMP_FV(9,4,4, 0,0,0) &amp;gt;= 0 %then ACCESSIBLE_GRAPH;
16         %mend;
17         FILENAME EGHTML TEMP;
18         ODS HTML5(ID=EGHTML) FILE=EGHTML
19             OPTIONS(BITMAP_MODE='INLINE')
20             %HTML5AccessibleGraphSupported
21             ENCODING='utf-8'
22             STYLE=HtmlBlue
23             NOGTITLE
24             NOGFOOTNOTE
25             GPATH=&amp;amp;sasworklocation
26         ;
NOTE: Writing HTML5(EGHTML) Body file: EGHTML
27         
28         options compress=yes reuse=yes;
29         
30         %macro ImportAndTranspose(
31               File=
32               , StartSheet=
33               , EndSheet=
34            );
35         
36            %local i;
37         
38            %do i = &amp;amp;StartSheet. %to &amp;amp;EndSheet.;
39         
40             %if &amp;amp;i=1 %then %do;
41         	
42             proc import datafile= "&amp;amp;File."
43                           out= sheet1
44                           dbms= xlsx
45                           replace;
46                   range= "Sheet1$A:X";
47                   getnames= yes;
48               run;
49         
50               proc sort data= sheet1;
51               by Type;
52               run;
53         	%end;
54         
55         	  %else %if &amp;amp;i= &amp;amp;EndSheet. %then %do;
56               proc import datafile= "&amp;amp;File."
57                           out= sheet&amp;amp;i.
2                                                          The SAS System                              14:42 Sunday, January 3, 2021

58                           dbms= xlsx
59                           replace;
60                   range= "Sheet&amp;amp;i.$A:AG";
61                   getnames= yes;
62               run;
63         
64               proc sort data= sheet&amp;amp;i.;
65               by Type;
66               run;
67         
68               proc transpose data= sheet&amp;amp;i.
69                     out= sheet&amp;amp;i._out(rename=(COL1=s&amp;amp;i. _NAME_=Year) drop=_label_);
70                  by Type;
71                  VAR '1988'N - '2019'N;
72               run;
73         	  proc print data=sheet&amp;amp;i._out;
74         	  run;
75         
76         	  data sheet&amp;amp;i._outx;
77         	  set sheet&amp;amp;i._out;
78               if s&amp;amp;i. in: ('NA', '$$') then s&amp;amp;i. =".";
79         	  run;
80         
81         	  %end;
82         
83         
84             %else %if (&amp;amp;i ne 1) and (&amp;amp;i ne Endsheet.) %then %do;
85               proc import datafile= "&amp;amp;File."
86                           out= sheet&amp;amp;i.
87                           dbms= xlsx
88                           replace;
89                   range= "Sheet&amp;amp;i.$A:AG";
90                   getnames= yes;
91               run;
92         
93               proc sort data= sheet&amp;amp;i.;
94               by Type;
95               run;
96         
97               proc transpose data= sheet&amp;amp;i.
98                     out= sheet&amp;amp;i._out(rename=(COL1=s&amp;amp;i. _NAME_=Year) drop=_label_);
99                  by Type;
100                 VAR '1988'N - '2019'N;
101              run;
102        	  proc print data=sheet&amp;amp;i._out;
103        	  run;
104        
105              DATA sheet&amp;amp;i._outx;
106              set sheet&amp;amp;i._out;
107        
108              if s&amp;amp;i. not in: ('NA', '$$') then s&amp;amp;i.2=input(s&amp;amp;i., 32.);
109        	  drop s&amp;amp;i.;
110              run;
111        	  %end;
112        
113        
114        
115           %end;
3                                                          The SAS System                              14:42 Sunday, January 3, 2021

116        
117        %mend;
118        
119        *Replicate all file in one folder;
120           data _null_;
121        length fref $8 fname $200;
122        did = filename(fref,'C:\Users\pnguyen\Desktop\New folder');
123        did = dopen(fref);
124        do i = 1 to dnum(did);
125          fname = dread(did,i);
126          cmd=catx(',', '%ImportAndTranspose(File=',
127              strip(fname), 'startsheet=1,endsheet=34);');
128          call execute(cmd);
129        end;
130        did = dclose(did);
131        did = filename(fref);
132        keep fname;
133        run;

ERROR: All positional parameters must precede keyword parameters.
ERROR: All positional parameters must precede keyword parameters.
ERROR: All positional parameters must precede keyword parameters.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

NOTE: CALL EXECUTE generated line.
NOTE: Line generated by the CALL EXECUTE routine.
1         +startsheet=1,endsheet=34);
           __________
           180

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the CALL EXECUTE routine.
2         +startsheet=1,endsheet=34);
           __________
           180

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the CALL EXECUTE routine.
3         +startsheet=1,endsheet=34);
           __________
           180

ERROR 180-322: Statement is not valid or it is used out of proper order.

134        
135        %LET _CLIENTTASKLABEL=;
136        %LET _CLIENTPROCESSFLOWNAME=;
137        %LET _CLIENTPROJECTPATH=;
138        %LET _CLIENTPROJECTPATHHOST=;
139        %LET _CLIENTPROJECTNAME=;
140        %LET _SASPROGRAMFILE=;
141        %LET _SASPROGRAMFILEHOST=;
4                                                          The SAS System                              14:42 Sunday, January 3, 2021

142        
143        ;*';*";*/;quit;run;
144        ODS _ALL_ CLOSE;
145        
146        
147        QUIT; RUN;
148  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;While I run the code of reading all filenames only, the code work successfully:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data filenames;
length fref $8 fname $200;
did = filename(fref,'H:\');
did = dopen(fref);
do i = 1 to dnum(did);
  fname = dread(did,i);
  output;
end;
did = dclose(did);
did = filename(fref);
keep fname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So I thought the problem occurring due to the added function called (execute) or else.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks and cheers!&lt;/P&gt;
&lt;DIV id="eJOY__extension_root" class="eJOY__extension_root_class" style="all: unset;"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sun, 03 Jan 2021 01:53:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709117#M217983</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-03T01:53:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709118#M217984</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212695"&gt;@Phil_NZ&lt;/a&gt;&amp;nbsp; - I've tweaked your command string - hopefully that will work better. If not add a&amp;nbsp; - put cmd = ; - statement to check the syntax:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  data _null_;
length fref $8 fname $200;
did = filename(fref,'C:\Users\pnguyen\Desktop\New folder');
did = dopen(fref);
do i = 1 to dnum(did);
  fname = dread(did,i);
  cmd=cats(%ImportAndTranspose(File=',
      strip(fname), ', startsheet=1, endsheet=34);');
  call execute(cmd);
end;
did = dclose(did);
did = filename(fref);
keep fname;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Jan 2021 03:12:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709118#M217984</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-01-03T03:12:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709119#M217985</link>
      <description>&lt;P&gt;Thank you very much for your help,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems that I no longer face the same problem, but also raising some other errors, I am wondering what is the problem there.&lt;/P&gt;
&lt;P&gt;Here is the log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;43         options compress=yes reuse=yes;
44         
45         %macro ImportAndTranspose(
46               File=
47               , StartSheet=
48               , EndSheet=
49            );
50         
51            %local i;
52         
53            %do i = &amp;amp;StartSheet. %to &amp;amp;EndSheet.;
54         
55             %if &amp;amp;i=1 %then %do;
56         	
57             proc import datafile= "&amp;amp;File."
2                                                          The SAS System                              14:42 Sunday, January 3, 2021

58                           out= sheet1
59                           dbms= xlsx
60                           replace;
61                   range= "Sheet1$A:X";
62                   getnames= yes;
63               run;
64         
65               proc sort data= sheet1;
66               by Type;
67               run;
68         	%end;
69         
70         	  %else %if &amp;amp;i= &amp;amp;EndSheet. %then %do;
71               proc import datafile= "&amp;amp;File."
72                           out= sheet&amp;amp;i.
73                           dbms= xlsx
74                           replace;
75                   range= "Sheet&amp;amp;i.$A:AG";
76                   getnames= yes;
77               run;
78         
79               proc sort data= sheet&amp;amp;i.;
80               by Type;
81               run;
82         
83               proc transpose data= sheet&amp;amp;i.
84                     out= sheet&amp;amp;i._out(rename=(COL1=s&amp;amp;i. _NAME_=Year) drop=_label_);
85                  by Type;
86                  VAR '1988'N - '2019'N;
87               run;
88         	  proc print data=sheet&amp;amp;i._out;
89         	  run;
90         
91         	  data sheet&amp;amp;i._outx;
92         	  set sheet&amp;amp;i._out;
93               if s&amp;amp;i. in: ('NA', '$$') then s&amp;amp;i. =".";
94         	  run;
95         
96         	  %end;
97         
98         
99             %else %if (&amp;amp;i ne 1) and (&amp;amp;i ne Endsheet.) %then %do;
100              proc import datafile= "&amp;amp;File."
101                          out= sheet&amp;amp;i.
102                          dbms= xlsx
103                          replace;
104                  range= "Sheet&amp;amp;i.$A:AG";
105                  getnames= yes;
106              run;
107        
108              proc sort data= sheet&amp;amp;i.;
109              by Type;
110              run;
111        
112              proc transpose data= sheet&amp;amp;i.
113                    out= sheet&amp;amp;i._out(rename=(COL1=s&amp;amp;i. _NAME_=Year) drop=_label_);
114                 by Type;
115                 VAR '1988'N - '2019'N;
3                                                          The SAS System                              14:42 Sunday, January 3, 2021

116              run;
117        	  proc print data=sheet&amp;amp;i._out;
118        	  run;
119        
120              DATA sheet&amp;amp;i._outx;
121              set sheet&amp;amp;i._out;
122        
123              if s&amp;amp;i. not in: ('NA', '$$') then s&amp;amp;i.2=input(s&amp;amp;i., 32.);
124        	  drop s&amp;amp;i.;
125              run;
126        	  %end;
127        
128        
129        
130           %end;
131        
132        %mend;
133        
134        *Replicate all file in one folder;
135           data _null_;
136        length fref $8 fname $200;
137        did = filename(fref,'C:\Users\pnguyen\Desktop\New folder');
138        did = dopen(fref);
139        do i = 1 to dnum(did);
140          fname = dread(did,i);
141          cmd=cats(%ImportAndTranspose(File=',
142              strip(fname),',startsheet=1,endsheet=34);');
NOTE: Line generated by the invoked macro "IMPORTANDTRANSPOSE".
142        proc import datafile= "&amp;amp;File."                    out= sheet1                   dbms= xlsx                    replace;
                ______                                       ___                                                         _______
                388                                          22                                                          388
                202                                                                                                      76
ERROR 388-185: Expecting an arithmetic operator.

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, 
              GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.  

ERROR 202-322: The option or parameter is not recognized and will be ignored.

ERROR 76-322: Syntax error, statement will be ignored.

142      ! proc import datafile= "&amp;amp;File."                    out= sheet1                   dbms= xlsx                    replace;
                                                                                           ____
                                                                                           22
142      !         range= "Sheet1$A:X";           getnames= yes;       run;              proc sort data= sheet1;       by Type;

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, 
              GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, [, ^=, {, |, ||, ~=.  

NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      


ERROR: File WORK.SHEET1.DATA does not exist.

4                                                          The SAS System                              14:42 Sunday, January 3, 2021

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      



ERROR: Physical file does not exist, C:\WINDOWS\system32\,      strip(fname),.
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
      

ERROR: File WORK.SHEET2.DATA does not exist.

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      


ERROR: File WORK.SHEET2.DATA does not exist.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And a further concern is: can I ask where I can write &lt;EM&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;put cmd = ;&lt;/SPAN&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/EM&gt; to check to the syntax in case needed ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks and warmest regards.&lt;/P&gt;
&lt;DIV id="eJOY__extension_root" class="eJOY__extension_root_class" style="all: unset;"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sun, 03 Jan 2021 03:25:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709119#M217985</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-03T03:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709120#M217986</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212695"&gt;@Phil_NZ&lt;/a&gt;&amp;nbsp; - This is how to check your command - it will just write the contents of cmd to your SAS log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length fref $8 fname $200;
did = filename(fref,'C:\Users\pnguyen\Desktop\New folder');
did = dopen(fref);
do i = 1 to dnum(did);
  fname = dread(did,i);
  cmd=cats(%ImportAndTranspose(File=',
      strip(fname), ', startsheet=1, endsheet=34);');
  put cmd = ;
  * call execute(cmd);
end;
did = dclose(did);
did = filename(fref);
keep fname;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Jan 2021 03:37:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709120#M217986</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-01-03T03:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to replicate work for all sheets in Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709121#M217987</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212695"&gt;@Phil_NZ&lt;/a&gt; - Oops there's a quote missing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length fref $8 fname $200;
did = filename(fref,'C:\Users\pnguyen\Desktop\New folder');
did = dopen(fref);
do i = 1 to dnum(did);
  fname = dread(did,i);
  cmd=cats('%ImportAndTranspose(File=',
      strip(fname), ', startsheet=1, endsheet=34);');
  put cmd = ;
  * call execute(cmd);
end;
did = dclose(did);
did = filename(fref);
keep fname;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Jan 2021 03:42:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/709121#M217987</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-01-03T03:42:26Z</dc:date>
    </item>
  </channel>
</rss>

