<?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: Concatenating name in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710122#M218539</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;I replace your code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let outfm = %substr(&amp;amp;outf,1,4)%substr(&amp;amp;outf,10,%eval(%length(&amp;amp;outf)-10));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;by&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let outfm = %substr(&amp;amp;outf,1,4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the result seems to be the same (&lt;STRONG&gt;without WARNING&lt;/STRONG&gt;)&lt;/P&gt;
&lt;P&gt;I am not sure whether my change is acceptable? or deleting the part "&lt;CODE class=" language-sas"&gt;%substr(&amp;amp;outf,10,%eval(%length(&amp;amp;outf)-10))"&amp;nbsp;&amp;nbsp;will&amp;nbsp;affect&amp;nbsp;any&amp;nbsp;other&amp;nbsp;part&amp;nbsp;of&amp;nbsp;the&amp;nbsp;macro&amp;nbsp;?&lt;/CODE&gt;&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>Fri, 08 Jan 2021 05:34:27 GMT</pubDate>
    <dc:creator>Phil_NZ</dc:creator>
    <dc:date>2021-01-08T05:34:27Z</dc:date>
    <item>
      <title>Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/709685#M218284</link>
      <description>&lt;P&gt;Hi SAS Users,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a code as below, to merge sheets (named sheet1, sheet2, ......) in one file and repeat it through two files in one folder ( Argentina_ and Bulgaria_). My outputs of interest are : "ARG_SHEETMERGE1, ARG_SHEETMERGE2, ARG_SHEETMERGE3, BUL_SHEETMERGE1, BUL_SHEETMERGE2, BUL_SHEETMERGE3" as the picture below:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="My97_0-1609960095357.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/53259i76362747722F456B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="My97_0-1609960095357.png" alt="My97_0-1609960095357.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I am wondering is there any way to adjust the code a little bit to get the result "ARG_MERGE1, ARG_MERGE2, ARG_MERGE3, BUL_MERGE1, BUL_MERGE2, BUL_MERGE3" without affecting other names (ARG_SHEET34_OUTX, ARG_SHEET34_OUT being stayed tune)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* Macro for all sheets in one file (from 1 to 34)*/
options compress=yes reuse=yes;

%macro ImportAndTranspose(
      File=
	  , outf=
      , 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= &amp;amp;outf.&amp;amp;i.
                  dbms= xlsx 
                  replace;
          range= "Sheet1$A:X";
          getnames= yes;
      run;
      
      proc sort data= &amp;amp;outf.&amp;amp;i.;
      by Type;
      run;
	%end;

	  %else %if &amp;amp;i= &amp;amp;EndSheet. %then %do;
      proc import datafile= "&amp;amp;File." 
                  out= &amp;amp;outf.&amp;amp;i.
                  dbms= xlsx 
                  replace;
          range= "Sheet&amp;amp;i.$A:AG";
          getnames= yes;
      run;
      
      proc sort data= &amp;amp;outf.&amp;amp;i.;
      by Type;
      run;

      proc transpose data= &amp;amp;outf.&amp;amp;i. 
            out= &amp;amp;outf.&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=&amp;amp;outf.&amp;amp;i._out;
	  run;

	  data &amp;amp;outf.&amp;amp;i._outx;
	  set &amp;amp;outf.&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= &amp;amp;outf.&amp;amp;i.
                  dbms= xlsx 
                  replace;
          range= "Sheet&amp;amp;i.$A:AG";
          getnames= yes;
      run;
      
      proc sort data= &amp;amp;outf.&amp;amp;i.;
      by Type;
      run;

      proc transpose data= &amp;amp;outf.&amp;amp;i. 
            out= &amp;amp;outf.&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=&amp;amp;outf.&amp;amp;i._out;
	  run;

      data &amp;amp;outf.&amp;amp;i._outx;
      set &amp;amp;outf.&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;
 /* Merging*/
  data &amp;amp;outf.merge1;
     merge
	  %do i =&amp;amp;StartSheet.+1 %to &amp;amp;EndSheet.-1;
	    &amp;amp;outf.&amp;amp;i._outx(keep= type year s&amp;amp;i.2)
	  %end;
	;
	by type year;
  run;

  data &amp;amp;outf.merge2;
     merge
	  &amp;amp;outf.merge1
	  &amp;amp;outf.&amp;amp;EndSheet._out (keep=type year s&amp;amp;EndSheet.)
	  ;
	 by type year;
  run;

 data &amp;amp;outf.merge3;
     merge
	  &amp;amp;outf.&amp;amp;StartSheet.
	  &amp;amp;outf.merge2 
	 ;
	 by type;
 run;

   
   
%mend;

/*Replicate all files in one folder*/

   data _null_;
length fref $8 fname $200;
did = filename(fref,'C:\Users\pnguyen\Desktop\New folder');

/*'fref' stands for File Reference and is limited to 8 chracters.*/
did = dopen(fref);
do i = 1 to dnum(did);
  fname = dread(did,i);
  short_fn= cats(substr(fname, 1,3),'_');
  cmd=cats('%ImportAndTranspose(File=C:\Users\pnguyen\Desktop\New folder\',
      strip(fname),',outf=',short_fn,'sheet,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;Many thanks and warmest regards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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>Wed, 06 Jan 2021 19:12:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/709685#M218284</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-06T19:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/709688#M218286</link>
      <description>&lt;P&gt;I suppose there is a way to tell sas to cycle through a set of sheets in a workbook, in order of appearance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But instead of defining a macro with STARTSHEET and ENDSHEET, you could pass two lists to the macro, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro exmpl(country_list=,sheetlist=);
  %do c=1 %to %sysfunc(countw(&amp;amp;country_list));
	%do s=1 %to %sysfunc(countw(&amp;amp;sheetlist));
	  %let sheetname=%scan(&amp;amp;country_list,&amp;amp;c)_%scan(&amp;amp;sheetlist,&amp;amp;s);

      /** Sheet-specific code here **/


	%end;
  %end;
%mend;
%exmpl(country_list=arg bul,sheetlist=sheetmerge1 sheetmerge2 sheetmerge3);

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of the benefits of this approach is that you don't have to rely on the order the sheets appear in the workbook.&amp;nbsp; Or course, this relies on having a two-level sheet naming convention.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 19:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/709688#M218286</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-01-06T19:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/709717#M218310</link>
      <description>&lt;P&gt;You are getting names like ARG_&lt;STRONG&gt;SHEET&lt;/STRONG&gt;MERGn because &amp;amp;outf is assigned&amp;nbsp;as&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;outf=',short_fn,'sheet&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I suggest to correct the &amp;amp;outf value for the MERGING part:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Merging*/
 %let outfm = %substr(&amp;amp;outf,1,4)%substr(&amp;amp;outf,10,%eval(%length(&amp;amp;outf)-10)); /* new line */
  data &amp;amp;outm.merge1;    /* line changed */
     merge
	  %do i =&amp;amp;StartSheet.+1 %to &amp;amp;EndSheet.-1;
	    &amp;amp;outf.&amp;amp;i._outx(keep= type year s&amp;amp;i.2)
	  %end;
	;
	by type year;
  run;

  data &amp;amp;outfm.merge2;    /* line changed */
     merge
	  &amp;amp;outfm.merge1    /* line changed */
	  &amp;amp;outf.&amp;amp;EndSheet._out (keep=type year s&amp;amp;EndSheet.)
	  ;
	 by type year;
  run;

 data &amp;amp;outfm.merge3;     /* line changed */
     merge
	  &amp;amp;outf.&amp;amp;StartSheet.
	  &amp;amp;outfm.merge2    /* line changed */
	 ;
	 by type;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 21:02:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/709717#M218310</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-06T21:02:44Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/709732#M218321</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;! Thank you very much for your solution, it goes directly to the problem!&lt;/P&gt;
&lt;P&gt;I haven't tested yet but to me, whether we need this line of code?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%substr(&amp;amp;outf,10,%eval(%length(&amp;amp;outf)-10));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can you please let me know why we need this code, 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>Wed, 06 Jan 2021 21:36:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/709732#M218321</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-06T21:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/709749#M218334</link>
      <description>&lt;P&gt;Only the merged datasets names contain the substring&amp;nbsp;&lt;STRONG&gt;sheetmerge&lt;/STRONG&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The goal is to cut out the&amp;nbsp;&lt;STRONG&gt;sheet&lt;/STRONG&gt; of that substring.&lt;/P&gt;
&lt;P&gt;First merge - only the merge output need correction.&lt;/P&gt;
&lt;P&gt;The 2nd and 3rd merge need correction for the output and for one of the inputs.&lt;/P&gt;
&lt;P&gt;So I preferred to create a new macro variable &amp;amp;outfm:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let outfm = %substr(&amp;amp;outf,1,4)%substr(&amp;amp;outf,10,%eval(%length(&amp;amp;outf)-10)); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;First part&amp;nbsp;&lt;STRONG&gt;&lt;CODE class=" language-sas"&gt;%substr(&amp;amp;outf,1,4)&lt;/CODE&gt;&lt;/STRONG&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;contains&amp;nbsp;for&amp;nbsp;example&amp;nbsp;ARG_&amp;nbsp;(4&amp;nbsp;characters).&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;The&amp;nbsp;2nd&amp;nbsp;part&amp;nbsp;need&amp;nbsp;skip&amp;nbsp;the&amp;nbsp;&lt;STRONG&gt;SHEET&lt;/STRONG&gt;&amp;nbsp;part&amp;nbsp;to&amp;nbsp;concatenate&amp;nbsp;the&amp;nbsp;final&amp;nbsp;part&amp;nbsp;which&amp;nbsp;length&amp;nbsp;depends&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;on&amp;nbsp;sheet&amp;nbsp;number&amp;nbsp;(one&amp;nbsp;or&amp;nbsp;two&amp;nbsp;digits)&amp;nbsp;-&amp;nbsp;it&amp;nbsp;starts&amp;nbsp;at&amp;nbsp;position&amp;nbsp;10&amp;nbsp;and&amp;nbsp;the&amp;nbsp;rest&amp;nbsp;length&amp;nbsp;is&amp;nbsp;calculated.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 22:06:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/709749#M218334</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-06T22:06:41Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/709780#M218346</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;Thank you very much for your replies and explanations, but there are some other things that happened when running this code:&lt;/P&gt;
&lt;P&gt;So, the code is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %let outfm = %substr(&amp;amp;outf,1,4)%substr(&amp;amp;outf,10,%eval(%length(&amp;amp;outf)-10));
  data &amp;amp;outfm.merge1;
     merge
	  %do i =&amp;amp;StartSheet.+1 %to &amp;amp;EndSheet.;
	    &amp;amp;outf.&amp;amp;i._outx(keep= type year s&amp;amp;i.)
	  %end;
	;
	by type year;
  run;


 data &amp;amp;outfm.merge2;
     merge
	  &amp;amp;outf.&amp;amp;StartSheet.
	  &amp;amp;outfm.merge1 
	 ;
	 by type;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;1. When I run this code, there are four warnings (compared to 0 warning previously)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WARNING: Argument 2 to macro function %SUBSTR is out of range.
WARNING: Argument 3 to macro function %SUBSTR is out of range.
WARNING: Argument 2 to macro function %SUBSTR is out of range.
WARNING: Argument 3 to macro function %SUBSTR is out of range.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2. Why we need to use %eval in this case, I did a lot of searches but can not find any document that explains the usage of %eval in macro that match your example. I am wondering if you can give me a quick description why we use the eval in the code below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let outfm = %substr(&amp;amp;outf,1,4)%substr(&amp;amp;outf,10,%eval(%length(&amp;amp;outf)-10));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3. Also the line of code above. From my understanding, you created a macro variable named outfm which is concatenated by two strings: "&lt;CODE class=" language-sas"&gt;%substr(&amp;amp;outf,1,4)"&amp;nbsp;and&amp;nbsp;"%substr(&amp;amp;outf,10,%eval(%length(&amp;amp;outf)-10))"&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;With the first string, let's say ARG_, at the second string, we skip the part "sheet1" or "sheet11" from outf. So, why don't we just use only the first part "%substr(&amp;amp;outf,1,4)" (meaning that if outf is &lt;STRONG&gt;ARG_SHEET&lt;/STRONG&gt;, we only get &lt;STRONG&gt;ARG_&lt;/STRONG&gt; and ignore the rest)&amp;nbsp; and ignore the second part because the names of the merged file (&amp;amp;outfm.merge1, &amp;amp;outfm.merge2) no longer relates to outf?&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>Thu, 07 Jan 2021 02:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/709780#M218346</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-07T02:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710122#M218539</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;I replace your code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let outfm = %substr(&amp;amp;outf,1,4)%substr(&amp;amp;outf,10,%eval(%length(&amp;amp;outf)-10));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;by&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let outfm = %substr(&amp;amp;outf,1,4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the result seems to be the same (&lt;STRONG&gt;without WARNING&lt;/STRONG&gt;)&lt;/P&gt;
&lt;P&gt;I am not sure whether my change is acceptable? or deleting the part "&lt;CODE class=" language-sas"&gt;%substr(&amp;amp;outf,10,%eval(%length(&amp;amp;outf)-10))"&amp;nbsp;&amp;nbsp;will&amp;nbsp;affect&amp;nbsp;any&amp;nbsp;other&amp;nbsp;part&amp;nbsp;of&amp;nbsp;the&amp;nbsp;macro&amp;nbsp;?&lt;/CODE&gt;&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>Fri, 08 Jan 2021 05:34:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710122#M218539</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-08T05:34:27Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710128#M218541</link>
      <description>&lt;P&gt;1) Relating to next message:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;WARNING: Argument 2 to macro function %SUBSTR is out of range.&lt;/PRE&gt;
&lt;P&gt;correct line (starting substring at position 10 means need subtract 9 from length)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let outfm = %substr(&amp;amp;outf,1,4)%substr(&amp;amp;outf,10,%eval(%length(&amp;amp;outf)-9));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2) You asked to change from ARG_&lt;STRONG&gt;SHEET&lt;/STRONG&gt;&lt;FONT color="#008000"&gt;MERGEn&lt;/FONT&gt; to ARG_&lt;FONT color="#339966"&gt;&lt;FONT color="#008000"&gt;MERGEn&lt;/FONT&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#339966"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#000000"&gt;Pay attention:&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT color="#339966"&gt;&amp;nbsp;&lt;FONT color="#000000"&gt;%substr(&amp;amp;outf,1,4)&amp;nbsp;contribute the ARG_ substring, while&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT color="#339966"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;FONT color="#339966"&gt;%substr(&amp;amp;outf,10,%eval(%length(&amp;amp;outf)-9));&lt;/FONT&gt;&amp;nbsp;contribute the &lt;FONT color="#008000"&gt;MERGEn. substring.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;3) The usage of %eval is to calculate the 2nd argument to the %substr function,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;otherwise&amp;nbsp; the generated code will be erroneous&amp;nbsp;&lt;/FONT&gt;&lt;FONT color="#000000"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%substr(&amp;amp;outf,10,15-9)); /* ARG_SHEETMERGE1 - is length 15 */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;instead the correct code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%substr(&amp;amp;outf,10,6);   /* length of MERGE1 */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;4) Result of above - if you omit the 2nd %substr, you will get dataset name as&amp;nbsp;&lt;STRONG&gt;ARG_&lt;/STRONG&gt;&amp;nbsp;only, and the 2nd merge will replace the output of the 1st merge etc.&lt;/P&gt;
&lt;P&gt;and next code will result in errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2021 06:30:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710128#M218541</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-08T06:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710136#M218546</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;I really appreciate your detailed explanation, and I learn a lot from that; however, I hope that we can make it clear a little bit then.&lt;/P&gt;
&lt;P&gt;1. Even when I change from 10 to 9 as the code you mentioned, such warnings still exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, I try to point out what really happended.&lt;/P&gt;
&lt;P&gt;2. Let's have a look back about the whole code in general:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ImportAndTranspose(
      File=
	  , outf=
      , 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= &amp;amp;outf.&amp;amp;i.
                  dbms= xlsx 
                  replace;
          range= "Sheet1$A:X";
          getnames= yes;
      run;
      
      proc sort data= &amp;amp;outf.&amp;amp;i.;
      by Type;
      run;
	%end;

	  %else %if &amp;amp;i= &amp;amp;EndSheet. %then %do;
      proc import datafile= "&amp;amp;File." 
                  out= &amp;amp;outf.&amp;amp;i.
                  dbms= xlsx 
                  replace;
          range= "Sheet&amp;amp;i.$A:AG";
          getnames= yes;
      run;
      
      proc sort data= &amp;amp;outf.&amp;amp;i.;
      by Type;
      run;

      proc transpose data= &amp;amp;outf.&amp;amp;i. 
            out= &amp;amp;outf.&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=&amp;amp;outf.&amp;amp;i._out;
	  run;

	  data &amp;amp;outf.&amp;amp;i._outx;
	  set &amp;amp;outf.&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= &amp;amp;outf.&amp;amp;i.
                  dbms= xlsx 
                  replace;
          range= "Sheet&amp;amp;i.$A:AG";
          getnames= yes;
      run;
      
      proc sort data= &amp;amp;outf.&amp;amp;i.;
      by Type;
      run;

      proc transpose data= &amp;amp;outf.&amp;amp;i. 
            out= &amp;amp;outf.&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=&amp;amp;outf.&amp;amp;i._out;
	  run;

      data &amp;amp;outf.&amp;amp;i._outx;
      set &amp;amp;outf.&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.;
	  rename s&amp;amp;i.2=s&amp;amp;i.;
      run;
	  %end;
	%end;
 /* Merging*/
%let outfm = %substr(&amp;amp;outf,1,4);
  data &amp;amp;outfm.merge1;
     merge
	  %do i =&amp;amp;StartSheet.+1 %to &amp;amp;EndSheet.;
	    &amp;amp;outf.&amp;amp;i._outx(keep= type year s&amp;amp;i.)
	  %end;
	;
	by type year;
  run;


 data &amp;amp;outfm.merge2;
     merge
	  &amp;amp;outf.&amp;amp;StartSheet.
	  &amp;amp;outfm.merge1 
	 ;
	 by type;
 run;

   
   
%mend;

/*Replicate all files 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);
  short_fn= cats(substr(fname, 1,3),'_');
  cmd=cats('%ImportAndTranspose(File=C:\Users\pnguyen\Desktop\New folder\',
      strip(fname),',outf=',short_fn,'sheet,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;So, for example, the filename( &lt;STRONG&gt;fref&lt;/STRONG&gt;) is &lt;STRONG&gt;Argentina_&lt;/STRONG&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp;then &lt;STRONG&gt;fname= Argentina_&lt;/STRONG&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp; then &lt;STRONG&gt;short_fn=Arg_&lt;/STRONG&gt;, then &lt;STRONG&gt;outf=Arg_sheet&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Therefore, when talking about the code under controversial:&lt;/P&gt;
&lt;P&gt;if the code is&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let outfm = %substr(&amp;amp;outf,1,4)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then &lt;STRONG&gt;outfm=Arg_&lt;/STRONG&gt;, then when merging, I will have two files &lt;STRONG&gt;Arg_merge1&lt;/STRONG&gt; and &lt;STRONG&gt;Arg_merge2&lt;/STRONG&gt; (because the data step is &lt;STRONG&gt;&amp;amp;outfm.merge1&lt;/STRONG&gt; and &lt;STRONG&gt;&amp;amp;outfm.merge2&lt;/STRONG&gt;).&lt;/P&gt;
&lt;P&gt;On the other hand, if we follow the code is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let outfm = %substr(&amp;amp;outf,1,4)%substr(&amp;amp;outf,10,%eval(%length(&amp;amp;outf)-9));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;At that time, l&lt;STRONG&gt;ength(outf)=length(Arg_sheet)=9&lt;/STRONG&gt;, and then, the &lt;SPAN&gt;&lt;STRONG&gt;2nd %substr&lt;/STRONG&gt; become redundant.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;I am wondering but I think the way I present the code confuse you. I think &lt;STRONG&gt;outf&lt;/STRONG&gt; in the code&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let outfm = %substr(&amp;amp;outf,1,4)%substr(&amp;amp;outf,10,%eval(%length(&amp;amp;outf)-9));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should be &lt;STRONG&gt;Arg_sheet&lt;/STRONG&gt; rather than &lt;STRONG&gt;Arg_sheetmerge1&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope that I can receive your idea about that.&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>Fri, 08 Jan 2021 09:10:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710136#M218546</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-08T09:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710149#M218552</link>
      <description>&lt;P&gt;1) Your statement "&lt;STRONG&gt;&lt;SPAN&gt;Even when I change from 10 to 9 as the code you mentioned, such warnings still exist." -&lt;/SPAN&gt;&lt;/STRONG&gt;&amp;nbsp;is not in the code you last posted:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt; /* Merging*/
%let outfm = %substr(&amp;amp;outf,1,4);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To examine the right situation I need you&amp;nbsp;to run the corrected code with OPTIONS MPRINT and post&lt;/P&gt;
&lt;P&gt;that part of the log that contains the generated&amp;nbsp;code and the messages relating to it .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Your code contains next lines:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Replicate all files 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);
  short_fn= cats(substr(fname, 1,3),'_');
  cmd=cats('%ImportAndTranspose(File=C:\Users\pnguyen\Desktop\New folder\',
      strip(fname),',outf=',short_fn,'sheet,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;This is not the code I posted to you. It seems that you made some mismatch between two diffrent posts you got. Pay attention to next two consecutive lines:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;STRONG&gt;did = filename(fref,'C:\.....');&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; did = dopen(fref);&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The first line is erroneous. anyway, the did will be replaced with the result of the 2nd line.&lt;/P&gt;
&lt;P&gt;3) The syntax of FILENAME statement is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;filename &amp;lt;fref&amp;gt; [&amp;lt;engine&amp;gt;] "&amp;lt;path and file name&amp;gt;";&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; In your case I suggest to replace the starting lines of your code with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mydir 'C:\Users\pnguyen\Desktop\New folder');
/* here fref is 'mydir' */
data _null_;
   did = dopen('mydir');
 ....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;4) If you code&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;%let outfm = %substr(&amp;amp;outf,1,4);&lt;/LI-CODE&gt;
&lt;P&gt;you can use - as you suggest - for merging: &amp;amp;outfm.MERG1 or &amp;amp;outfm.MERGE2 etc.&lt;/P&gt;
&lt;P&gt;I admit it makes logic and shortens the code.&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2021 11:29:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710149#M218552</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-08T11:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710275#M218618</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;.Thank you very much for your dedicated helps. Following your guide, I have some replies here&lt;/P&gt;
&lt;P&gt;1. When I run &lt;STRONG&gt;OPTIONS MPRINT&lt;/STRONG&gt; with the corrected code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let outfm = %substr(&amp;amp;outf,1,4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The associated log is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;93        +
data Arg_merge1;      merge      Arg_sheet2_outx(keep= type year s2)      Arg_sheet3_outx(keep= type year s3
94        +)      Arg_sheet4_outx(keep= type year s4)      Arg_sheet5_outx(keep= type year s5)      Arg_sheet6_outx(keep= type year 
s6)      Arg_sheet7_outx(keep= type year s7)      Arg_sheet8_outx(keep= type year s8)      Arg_sheet9_outx(keep= type year s9)
95        + Arg_sheet10_outx(keep= type year s10)      Arg_sheet11_outx(keep= type year s11)      Arg_sheet12_outx(keep= type year 
s12)      Arg_sheet13_outx(keep= type year s13)      Arg_sheet14_outx(keep= type year s14)      Arg_sheet15_outx(keep= type year 
s15)
96        +    Arg_sheet16_outx(keep= type year s16)      Arg_sheet17_outx(keep= type year s17)      Arg_sheet18_outx(keep= type 
year s18)      Arg_sheet19_outx(keep= type year s19)      Arg_sheet20_outx(keep= type year s20)      Arg_sheet21_outx(keep= type 
year s21
97        +)      Arg_sheet22_outx(keep= type year s22)      Arg_sheet23_outx(keep= type year s23)      Arg_sheet24_outx(keep= type 
year s24)      Arg_sheet25_outx(keep= type year s25)      Arg_sheet26_outx(keep= type year s26)      Arg_sheet27_outx(keep= type 
year
98        + s27)      Arg_sheet28_outx(keep= type year s28)      Arg_sheet29_outx(keep= type year s29)      Arg_sheet30_outx(keep= 
type year s30)      Arg_sheet31_outx(keep= type year s31)      Arg_sheet32_outx(keep= type year s32)      Arg_sheet33_outx(keep= 
type
99        + year s33)      Arg_sheet34_outx(keep= type year s34)  ;  by type year;   run;

NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET2_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET3_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET4_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET5_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET6_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET7_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET8_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET9_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET10_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET11_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET12_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET13_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET14_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET15_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET16_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET17_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET18_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET19_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET20_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET21_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET22_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET23_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET24_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET25_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET26_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET27_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET28_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET29_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET30_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET31_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET32_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET33_OUTX.
NOTE: There were 14496 observations read from the data set WORK.ARG_SHEET34_OUTX.
NOTE: The data set WORK.ARG_MERGE1 has 14496 observations and 35 variables.
NOTE: Compressing data set WORK.ARG_MERGE1 decreased size by 38.89 percent. 
      Compressed is 44 pages; un-compressed would require 72 pages.
NOTE: DATA statement used (Total process time):
      real time           0.25 seconds
      cpu time            0.21 seconds
      

99        +                                                                                  data Arg_merge2;      merge    
Arg_sheet1    Arg_merge1    ;   by type;  run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please let me know unless it is the &lt;STRONG&gt;LOG&lt;/STRONG&gt; you mentioned &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Regarding the second point, I think it was what you suggest to me from the previous topic, maybe I did not get your idea thoroughly last time or the way I present my data confused you, but if it is the case, could you please tell me why you prefer the new version rather than from the previous post (&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708535#M217766" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708535#M217766&lt;/A&gt;)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You said this version has problems with the function&amp;nbsp;&lt;STRONG&gt;filename&lt;/STRONG&gt; but as I saw from the document (&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n15scht124hr4nn1g296cqg2kqfa.htm&amp;amp;locale=en"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n15scht124hr4nn1g296cqg2kqfa.htm&amp;amp;locale=en&lt;/A&gt;), there seems to be nothing wrong with the code itself per se. So let's say in the last version, you suggest me to use&lt;STRONG&gt; filename as a function&lt;/STRONG&gt; and now we use &lt;STRONG&gt;filename as a statement&lt;/STRONG&gt;. And I value both approaches but I am not sure why you said that the previous one is wrong (&lt;STRONG&gt;filename&lt;/STRONG&gt; as a function)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yeah, and I also check the new code you suggested&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mydir 'C:\Users\pnguyen\Desktop\New folder';
data _null_;
did = dopen('mydir');
do i = 1 to dnum(did);
  fname = dread(did,i);
  short_fn= cats(substr(fname, 1,3),'_');
  cmd=cats('%ImportAndTranspose(File=C:\Users\pnguyen\Desktop\New folder\',
      strip(fname),',outf=',short_fn,'sheet,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;And yeah, thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;, it works well without any error.&lt;/P&gt;
&lt;P&gt;And regarding the code right above, I think I also can delete the line of code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;did = filename(fref);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;without causing any error? am I correct about that? (I ran the full code without this line of code and the result seems not to be changed, I am just not sure if this exclusion causes any hidden error that I am incapable to spot out)&lt;/P&gt;
&lt;P&gt;To me, between the two versions, I prefer the new version because it is straightforward.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;, thank to you and other SAS helpers, I can learn and improve a lot. Many thanks again!&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>Fri, 08 Jan 2021 20:24:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710275#M218618</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-08T20:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710290#M218621</link>
      <description>&lt;P&gt;Using the FILENAME statement to define the fileref is fine. The main reasons to use the FILENAME() function would be if you had a list of files that you want to process instead of just the one file (directory actually) in your example.&amp;nbsp; Also with the FILENAME() function your code could capture the return code and perhaps handle errors or at least generate a more meaningful message when the fileref cannot be created.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similarly not clearing the fileref should not matter in your case.&amp;nbsp; Again if you are processing a lot of files then it is more important to clear the filerefs you are no longer using if for no other reason that to remove clutter from your SAS environment.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2021 20:53:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710290#M218621</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-08T20:53:39Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710296#M218626</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your insightful idea and discussion!. However, the filename statement also can work with a list of files (at least I tested with two files in one folder and it worked).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apart from that, can I ask whether &lt;STRONG&gt;fref&lt;/STRONG&gt; is the abbreviation of &lt;STRONG&gt;fileref&lt;/STRONG&gt;, because I did quite a bit searches and the word "&lt;STRONG&gt;fref&lt;/STRONG&gt;" is not really popularly-used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And, regarding &lt;STRONG&gt;"fref"&lt;/STRONG&gt; clearance, because when I use the code above, I do not contain &lt;STRONG&gt;fref&lt;/STRONG&gt; so I just exclude this code, please correct me if I get your idea mistakenly.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mydir 'C:\Users\pnguyen\Desktop\New folder';
data _null_;
did = dopen('mydir');
do i = 1 to dnum(did);
  fname = dread(did,i);
  short_fn= cats(substr(fname, 1,3),'_');
  cmd=cats('%ImportAndTranspose(File=C:\Users\pnguyen\Desktop\New folder\',
      strip(fname),',outf=',short_fn,'sheet,startsheet=1,endsheet=34);');
  call execute(cmd);
end;
did = dclose(did);
/*did = filename(fref);*/     /* I delete this line of code because fref does not exist above*/
keep fname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you mean, in my case, I need to write the associated code below?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;did = filename(mydir);&lt;/CODE&gt;&lt;/PRE&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>Fri, 08 Jan 2021 21:09:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710296#M218626</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-08T21:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710306#M218628</link>
      <description>&lt;P&gt;A fileref is the name you assigned that points the directory you are trying to scan for files. In your program you are using MYDIR as your fileref.&amp;nbsp; In your program you can use a FILENAME statement after the data step to clear the MYDIR fileref:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mydir ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;FREF was the name of a variable in a data step. Clearing the value of the variable does nothing meaningful in a data step that is not writing out any observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have no idea where you are seeing multiples files. Your current program is only pointing MYDIR at a single filename (directory).&amp;nbsp; You can reuse the same fileref over and over to point to multiple files, but only one at a time.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mydir 'C:\Users\pnguyen\Desktop\New folder';
filename mydir 'C:\Users\pnguyen\Desktop\Another folder';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the posted program is not doing that anyway.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also point a single filref at multiple directories,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mydir
  ( 'C:\Users\pnguyen\Desktop\New folder'
    'C:\Users\pnguyen\Desktop\Another folder'
  )
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but I don't think that would work well in this program where you are trying to use the DOPEN() and DREAD() functions to list the files in the directory that the fileref points to.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2021 21:33:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710306#M218628</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-08T21:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710313#M218632</link>
      <description>&lt;P&gt;1) You can neglect point 1 as I accepted your clarification of ignoring the 2nd %substr.&lt;/P&gt;
&lt;P&gt;2) In your first post&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708535#M217766" target="_self"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-replicate-work-for-all-sheets-in-Excel/m-p/708535#M217766&lt;/A&gt;&amp;nbsp;you added next code as a reply to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13593"&gt;@Andreas&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*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;I was focusing on the preceding code only and did not noticed details of that part, just copied it as is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I prefer now to focus on issues you have now, instead of focusing on the history of the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) Relating to&amp;nbsp;&lt;STRONG&gt;FILENAME&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; On a second thought I understand the confusion - mine as yours.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;There are two methods to assign a file reference (FileRef or fref) to a physical file or directory:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; a) A preceding declaration statement. Its syntax is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FILENAME &amp;lt;fileref&amp;gt; [&amp;lt;engine&amp;gt;] "&amp;lt;path&amp;gt;[&amp;lt;file name&amp;gt;]";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; b) A SAS function, as shown in the documentation you posted the link:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rc = FILENAME(fileref, filename &amp;lt;,device-type&amp;gt; &amp;lt;, 'host-options'&amp;gt;
&amp;lt;, directory-reference&amp;gt;);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;pay attention to the documentation line&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;fileref
specifies the fileref to assign to the external file. &lt;BR /&gt;In a DATA step, fileref can be a character expression, &lt;BR /&gt;   a string enclosed in single quotation marks that specifies the fileref, or &lt;BR /&gt;   a DATA step variable whose value contains the fileref. &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &lt;STRONG&gt;rc&lt;/STRONG&gt; stands for Return Code. In case of file or directory not found (or other reasons) RC will contain an error code &amp;gt; 0. Zero means assignment was done successfully.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use any of next methods, either&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mydir 'C:\Users\pnguyen\Desktop\New folder';
data _null_;
did = dopen('mydir');
do i = 1 to dnum(did);
   .......&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;OR&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   rc = filename('mydir','C:\Users\pnguyen\Desktop\New folder');
   did = dopen('mydir');
   do i = 1 to dnum(did);
     .........&lt;BR /&gt;   end;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;did&amp;nbsp;=&amp;nbsp;dclose(did);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;rc&amp;nbsp;=&amp;nbsp;filename('mydir');&amp;nbsp;/*&amp;nbsp;optionl - clears&amp;nbsp;the&amp;nbsp;file&amp;nbsp;refernce,&amp;nbsp;disconnects&amp;nbsp;it&amp;nbsp;from&amp;nbsp;the&amp;nbsp;file/directory&amp;nbsp;*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;OR&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   fref = 'mydir';
   rc = filename(fref,'C:\Users\pnguyen\Desktop\New folder');
   did = dopen(fref);
   do i = 1 to dnum(did);
     .........&lt;BR /&gt;   end;&lt;BR /&gt;   did = dclose(did);&lt;BR /&gt;   did = filename(fref);&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&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>Fri, 08 Jan 2021 22:09:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710313#M218632</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-08T22:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710345#M218650</link>
      <description>&lt;P&gt;Awesome, thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;, I think we are about to go to an end&lt;/P&gt;
&lt;P&gt;I have some questions relating to the code a bit, I want to talk about the very first option&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mydir 'C:\Users\pnguyen\Desktop\New folder';
data _null_;
did = dopen('mydir');
do i = 1 to dnum(did);
   .......&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;1. So, "did" here means that we open the directory, am I correct? Is there anything special that the word"did" stand for?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Apart from that, I am wondering why you open the directory 'mydir' but not close afterward?&lt;/P&gt;
&lt;P&gt;I mean, should I delete the codeline&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;did = dclose(did);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in the code below?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
did = dopen('mydir');
do i = 1 to dnum(did);
  fname = dread(did,i);
  short_fn= cats(substr(fname, 1,3),'_');
  cmd=cats('%ImportAndTranspose(File=C:\Users\pnguyen\Desktop\New folder\',
      strip(fname),',outf=',short_fn,'sheet,startsheet=1,endsheet=34);');
  call execute(cmd);
end;
did = dclose(did);
keep fname;&lt;BR /&gt;run;&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>Sat, 09 Jan 2021 03:53:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710345#M218650</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-09T03:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710346#M218651</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From my focal point, with the code below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mydir 'C:\Users\pnguyen\Desktop\New folder';
data _null_;
did = dopen('mydir');
do i = 1 to dnum(did);
  fname = dread(did,i);
  short_fn= cats(substr(fname, 1,3),'_');
  cmd=cats('%ImportAndTranspose(File=C:\Users\pnguyen\Desktop\New folder\',
      strip(fname),',outf=',short_fn,'sheet,startsheet=1,endsheet=34);');
  call execute(cmd);
end;
did = dclose(did);
keep fname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I think because "&lt;STRONG&gt;mydir&lt;/STRONG&gt;" overthere is assign to a &lt;STRONG&gt;whole folder, not a specific file&lt;/STRONG&gt;. Therefore, we open "&lt;STRONG&gt;mydir&lt;/STRONG&gt;", we open all the files inside this folder. Then, if we have three files in this folder, &lt;STRONG&gt;dnum(did)=3&lt;/STRONG&gt;. Then the codes following will execute multiple files. It is my understanding, aligning with the results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not sure whether I fell into any fallacy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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>Sat, 09 Jan 2021 04:02:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710346#M218651</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-09T04:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710352#M218654</link>
      <description>&lt;P&gt;1) &lt;STRONG&gt;did&lt;/STRONG&gt; stands for Directory-ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; If it was a file (not a directory) I would use&amp;nbsp;&lt;STRONG&gt;fid&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Both are assigned a value through&amp;nbsp;&lt;STRONG&gt;dopen&lt;/STRONG&gt; (&lt;STRONG&gt;fopen&lt;/STRONG&gt;) functions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Anyhow you can use any valid SAS variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; In both cases it contains a positive sequence number of filenames starting at 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; It is reset to zero when closed by dclose or fclose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; There are some functions to get information from the directory or the file, like&amp;nbsp;&lt;STRONG&gt;dnum&lt;/STRONG&gt; you already used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; 2) You open a directory by&amp;nbsp;&lt;STRONG&gt;dopen. &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; By closing it (by&amp;nbsp;&lt;STRONG&gt;dclose&lt;/STRONG&gt;) you release the resources used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jan 2021 06:56:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710352#M218654</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-09T06:56:23Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710397#M218677</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I think because "&lt;/SPAN&gt;&lt;STRONG&gt;mydir&lt;/STRONG&gt;&lt;SPAN&gt;" overthere is assign to a&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;whole folder, not a specific file&lt;/STRONG&gt;&lt;SPAN&gt;. Therefore, we open "&lt;/SPAN&gt;&lt;STRONG&gt;mydir&lt;/STRONG&gt;&lt;SPAN&gt;", we open all the files inside this folder. Then, if we have three files in this folder,&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;dnum(did)=3&lt;/STRONG&gt;&lt;SPAN&gt;. Then the codes following will execute multiple files. It is my understanding, aligning with the results.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;It helps to understand what a directory actually is in terms of how the file system works.&amp;nbsp; A directory is actually just a special kind of file. What is stored in the file is the names of the files that exist in that directory along with other metadata about the files.&amp;nbsp; By opening the fileref MYDIR with the DOPEN() function instead of FOPEN() function you can read the list this metadata about the files. But you not opening the actual individual files themselves. You are just reading the directory itself so you pull out the names of the files that exist in that directory.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jan 2021 19:19:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-name-in-macro/m-p/710397#M218677</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-09T19:19:35Z</dc:date>
    </item>
  </channel>
</rss>

