<?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: Running macro for each file in folder(for Multiple files) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/446834#M282962</link>
    <description>&lt;P&gt;Thank you. Its working fine&lt;/P&gt;</description>
    <pubDate>Mon, 19 Mar 2018 15:41:45 GMT</pubDate>
    <dc:creator>SAS_PA1</dc:creator>
    <dc:date>2018-03-19T15:41:45Z</dc:date>
    <item>
      <title>Running macro for each file in folder(for Multiple files)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444492#M282951</link>
      <description>&lt;P&gt;For the below code I am getting error, please suggest me the changes. Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro LOOP;&lt;BR /&gt;%global fname2 fname;&lt;BR /&gt;%DO I=1 %TO &amp;amp;TOTOBS;&lt;BR /&gt;data _Null_;&lt;BR /&gt;set compnm (Firstobs=&amp;amp;I obs=&amp;amp;i);&lt;BR /&gt;call SYMPUT('fname2',trim(fname));&lt;BR /&gt;run;&lt;BR /&gt;%put &amp;amp;fname2;&lt;BR /&gt;%internal_db_Mh_Prod1(&amp;amp;i,&amp;amp;fname2);&lt;BR /&gt;%END;&lt;BR /&gt;%MEND LOOP;&lt;BR /&gt;%LOOP;&lt;/P&gt;&lt;P&gt;Data Med_Cases;&lt;BR /&gt;Set PDATA_1-PDATA_%TRIM(&amp;amp;TOTOBS);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Proc sort ; by Task_datetime;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Proc datasets;&lt;BR /&gt;Delete PDATA_1-PDATA_%TRIM(&amp;amp;TOTOBS);&lt;BR /&gt;delete compnm;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LOG FILE ERROR&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4169 records were read from the infile PDATA.&lt;BR /&gt;The minimum record length was 77.&lt;BR /&gt;The maximum record length was 111.&lt;BR /&gt;NOTE: The data set WORK.PDATA_109 has 2132 observations and 8 variables.&lt;BR /&gt;NOTE: Compressing data set WORK.PDATA_109 decreased size by 40.00 percent.&lt;BR /&gt;Compressed is 6 pages; un-compressed would require 10 pages.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 45.00 seconds&lt;BR /&gt;cpu time 0.02 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;119&lt;BR /&gt;120 Data Med_Cases;&lt;BR /&gt;121 Set&lt;BR /&gt;121 ! PDATA_1-PDATA_%TRIM(&amp;amp;TOTOBS);&lt;BR /&gt;NOTE: Autocall member, TRIM, has not been compiled by the macro processor. It might contain a macro syntax error or not define a&lt;BR /&gt;macro with the same name as the member. To autocall this member again, set OPTION MRECALL.&lt;BR /&gt;121 (&amp;amp;TOTOBS);&lt;BR /&gt;_&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, _DATA_, _LAST_, _NULL_.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;122&lt;BR /&gt;123&lt;/P&gt;&lt;P&gt;NOTE: Compression was disabled for data set WORK.MED_CASES because compression overhead would increase the size of the data set.&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Mar 2018 01:56:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444492#M282951</guid>
      <dc:creator>SAS_PA1</dc:creator>
      <dc:date>2018-03-11T01:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro for each file in folder(for Multiple files)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444514#M282952</link>
      <description>&lt;P&gt;You have a problem with the %trim macro.&lt;/P&gt;
&lt;P&gt;1. How do you create TOTOBS?&lt;/P&gt;
&lt;P&gt;2. What happens if you don't use&amp;nbsp; %trim ?&lt;/P&gt;</description>
      <pubDate>Sun, 11 Mar 2018 03:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444514#M282952</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-03-11T03:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro for each file in folder(for Multiple files)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444519#M282953</link>
      <description>data compnm;&lt;BR /&gt;infile compnm ;&lt;BR /&gt;input fname $46.;&lt;BR /&gt;put _infile_;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;set compnm;&lt;BR /&gt;CALL SYMPUT( 'TOTOBS' , _N_ );&lt;BR /&gt;%put &amp;amp;TOTOBS;&lt;BR /&gt;run;</description>
      <pubDate>Sun, 11 Mar 2018 04:38:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444519#M282953</guid>
      <dc:creator>SAS_PA1</dc:creator>
      <dc:date>2018-03-11T04:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro for each file in folder(for Multiple files)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444522#M282954</link>
      <description>&lt;P&gt;Try to use symputx instead of symput, and do not call %trim&lt;/P&gt;</description>
      <pubDate>Sun, 11 Mar 2018 05:31:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444522#M282954</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-03-11T05:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro for each file in folder(for Multiple files)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444530#M282955</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/169801"&gt;@SAS_PA1&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Looking at your code what you're trying to achieve with the %TRIM() macro is to left align the value in macro var &amp;amp;TOTOBS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%TRIM() doesn't give you that. TRIM is "cutting off" trailing blanks but you want to "cut off" leading blanks. That's done with the LEFT function or on a macro level you can also use the OOTB function style macro %LEFT()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even though %TRIM is not the appropriate macro in first place it's still a bit worrying that %TRIM() throws a syntax error. This is an OOTB SAS macro. "Someone" must have overwritten/overlayed it with invalid syntax. If it wasn't you then "someone" at your site messed up the SAS environment. Contact your SAS Admin as this needs fixing.&lt;/P&gt;
&lt;P&gt;By setting&amp;nbsp;&lt;FONT color="#0000ff" face="Courier New"&gt;options&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;mautolocdisplay&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&amp;nbsp;in your code you'll see in the log where from a macro has been picked up. The path you should see for %trim() and %left is something like ...\SASFoundation\9.4\core\sasmacro\trim.sas&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And last but not least go for what &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;proposes and ensure that the values are left aligned when populating the macro var by using symputx(). In doing so you won't need %trim() or %left() at all in your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Mar 2018 09:59:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444530#M282955</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-03-11T09:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro for each file in folder(for Multiple files)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444559#M282956</link>
      <description>&lt;P&gt;Where did you define the TOTOBS macro variable?&amp;nbsp; It is not set in the code you posted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps something more like this for your %LOOP macro?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro LOOP;
%if not %symexist(totobs) %then %global totobs;
data _null_;
  if eof then call symputx('totobs',put(_n_-1,32.));
  set compnm end=eof ;
  call execute(cats('%nrstr(%internal_db_Mh_Prod1)(',_n_,',',fname,')'));
run;
%mend LOOP;
%LOOP;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Although in that case why make it a macro at all?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  if eof then call symputx('totobs',put(_n_-1,32.));
  set compnm end=eof ;
  call execute(cats('%nrstr(%internal_db_Mh_Prod1)(',_n_,',',fname,')'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 11 Mar 2018 16:14:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444559#M282956</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-11T16:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro for each file in folder(for Multiple files)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444561#M282957</link>
      <description>&lt;P&gt;The code that which I have provide in the beginning its working fine using FTP command, when I am using with sftp I am getting provided Log error&lt;/P&gt;&lt;P&gt;filename compnm &lt;STRONG&gt;sftp&lt;/STRONG&gt; ''ls cd= /path&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data compnm;&lt;BR /&gt;infile compnm ;&lt;BR /&gt;input fname $46.;&lt;BR /&gt;put _infile_;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set compnm;&lt;BR /&gt;CALL SYMPUT( 'TOTOBS' , _N_ );&lt;BR /&gt;%put &amp;amp;TOTOBS;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Mar 2018 16:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444561#M282957</guid>
      <dc:creator>SAS_PA1</dc:creator>
      <dc:date>2018-03-11T16:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro for each file in folder(for Multiple files)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444564#M282958</link>
      <description>&lt;P&gt;1) Do not use call symput() instead of call symputx(), unless you really really really want to make macro variables with leading and/or trailing spaces in them.&lt;/P&gt;
&lt;P&gt;2) Don't reference a macro variable before it has been created!.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set compnm end=eof;
  if eof then do;
     CALL SYMPUTX( 'TOTOBS' , _N_ );
     CALL SYMPUT( 'BAD_TOTOBS' , _N_ );
  end;
run;

%put |&amp;amp;TOTOBS| |&amp;amp;BAD_TOTOBS|;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Mar 2018 17:14:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444564#M282958</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-11T17:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro for each file in folder(for Multiple files)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444566#M282959</link>
      <description>&lt;P&gt;Refrencing Macro variable after it has created below is the code format. Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;filename compnm&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;sftp&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;''ls cd= /path&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data compnm;&lt;BR /&gt;infile compnm ;&lt;BR /&gt;input fname $46.;&lt;BR /&gt;put _infile_;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set compnm;&lt;BR /&gt;CALL SYMPUT( 'TOTOBS' , _N_ );&lt;BR /&gt;%put &amp;amp;TOTOBS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; &lt;STRONG&gt;&lt;EM&gt;LOOP&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;%global fname2 fname;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %DO I=&lt;STRONG&gt;1&lt;/STRONG&gt; %TO &amp;amp;TOTOBS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data _Null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set compnm (Firstobs=&amp;amp;I obs=&amp;amp;i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call SYMPUT('fname2',trim(fname));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;fname2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %&lt;STRONG&gt;&lt;EM&gt;internal_db_Mh_Prod1&lt;/EM&gt;&lt;/STRONG&gt;(&amp;amp;i,&amp;amp;fname2);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %END;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%MEND&lt;/STRONG&gt; LOOP;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;LOOP&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt; Medhok_Cases;&lt;/P&gt;&lt;P&gt;Set PDATA_1-PDATA_%&lt;STRONG&gt;&lt;EM&gt;TRIM&lt;/EM&gt;&lt;/STRONG&gt;(&amp;amp;TOTOBS);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Proc&lt;/STRONG&gt; &lt;STRONG&gt;sort&lt;/STRONG&gt; ; by Task_datetime;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Proc&lt;/STRONG&gt; &lt;STRONG&gt;datasets&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;Delete PDATA_1-PDATA_%&lt;STRONG&gt;&lt;EM&gt;TRIM&lt;/EM&gt;&lt;/STRONG&gt;(&amp;amp;TOTOBS);&lt;/P&gt;&lt;P&gt;delete compnm;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Run&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Mar 2018 17:53:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444566#M282959</guid>
      <dc:creator>SAS_PA1</dc:creator>
      <dc:date>2018-03-11T17:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro for each file in folder(for Multiple files)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444570#M282960</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/169801"&gt;@SAS_PA1&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Refrencing Macro variable after it has created below is the code format. Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;filename compnm&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;sftp&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;''ls cd= /path&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data compnm;&lt;BR /&gt;infile compnm ;&lt;BR /&gt;input fname $46.;&lt;BR /&gt;put _infile_;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;set compnm;&lt;BR /&gt;CALL SYMPUT( 'TOTOBS' , _N_ );&lt;BR /&gt;%put &amp;amp;TOTOBS;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; &lt;STRONG&gt;&lt;EM&gt;LOOP&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;%global fname2 fname;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %DO I=&lt;STRONG&gt;1&lt;/STRONG&gt; %TO &amp;amp;TOTOBS;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data _Null_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set compnm (Firstobs=&amp;amp;I obs=&amp;amp;i);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call SYMPUT('fname2',trim(fname));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;fname2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %&lt;STRONG&gt;&lt;EM&gt;internal_db_Mh_Prod1&lt;/EM&gt;&lt;/STRONG&gt;(&amp;amp;i,&amp;amp;fname2);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %END;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;%MEND&lt;/STRONG&gt; LOOP;&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;LOOP&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt; Medhok_Cases;&lt;/P&gt;
&lt;P&gt;Set PDATA_1-PDATA_%&lt;STRONG&gt;&lt;EM&gt;TRIM&lt;/EM&gt;&lt;/STRONG&gt;(&amp;amp;TOTOBS);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Proc&lt;/STRONG&gt; &lt;STRONG&gt;sort&lt;/STRONG&gt; ; by Task_datetime;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Proc&lt;/STRONG&gt; &lt;STRONG&gt;datasets&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;Delete PDATA_1-PDATA_%&lt;STRONG&gt;&lt;EM&gt;TRIM&lt;/EM&gt;&lt;/STRONG&gt;(&amp;amp;TOTOBS);&lt;/P&gt;
&lt;P&gt;delete compnm;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You don't seem to be reading any of the replies to your question.&amp;nbsp; &amp;nbsp;Have you tried making the changes suggested?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you still have a %PUT &amp;amp;TOTOBS statement in the middle of the data step that is going to set the value of that macro variable when it runs?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You start defining a DATA _NULL step and then before finishing it, so that SAS can run it, you add&lt;/P&gt;
&lt;P&gt;1) A %PUT&lt;/P&gt;
&lt;P&gt;2) A %macro definition block.&lt;/P&gt;
&lt;P&gt;3) A call do the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;So when the %LOOP macro runs the data _NULL_ step has NOT YET RUN and the macro variable TOTOBS had not been created.&lt;/STRONG&gt;&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;data_null_;
  set compnm;
  CALL SYMPUTX( 'TOTOBS' , _N_ );
run;

%put &amp;amp;TOTOBS;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Mar 2018 18:22:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444570#M282960</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-11T18:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro for each file in folder(for Multiple files)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444586#M282961</link>
      <description>&lt;P&gt;You really should end any data step and proc step with a RUN; command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below code bit...&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set compnm;
CALL SYMPUT( 'TOTOBS' , _N_ );
%put &amp;amp;TOTOBS;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;....would be more efficient and actually do what you're after if coded like...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  CALL SYMPUTx( 'TOTOBS' , nobs );
  stop;
  set compnm nobs=nobs;
run;

%put &amp;amp;TOTOBS;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 11 Mar 2018 20:33:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/444586#M282961</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-03-11T20:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro for each file in folder(for Multiple files)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/446834#M282962</link>
      <description>&lt;P&gt;Thank you. Its working fine&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 15:41:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-for-each-file-in-folder-for-Multiple-files/m-p/446834#M282962</guid>
      <dc:creator>SAS_PA1</dc:creator>
      <dc:date>2018-03-19T15:41:45Z</dc:date>
    </item>
  </channel>
</rss>

