<?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: Macro error in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71057#M20506</link>
    <description>Thanks Scott!&lt;BR /&gt;
&lt;BR /&gt;
I changed the code to use PUT statement instead. But I'm getting some error in the log file indicating the PUT used in the macro is not used in the right context.&lt;BR /&gt;
&lt;BR /&gt;
Below is my code fragment containing the macro and the macro invocation block...&lt;BR /&gt;
&lt;BR /&gt;
------------------------------------------------------------------------------------------------&lt;BR /&gt;
/* Setup libref to execute the ftp command                     */&lt;BR /&gt;
filename ftpcmds "&amp;amp;ftpcmds";&lt;BR /&gt;
&lt;BR /&gt;
%macro MD(DIR);&lt;BR /&gt;
%LET COUNT=0;&lt;BR /&gt;
%LET DLM=\;&lt;BR /&gt;
&lt;BR /&gt;
%DO J=1 %TO %LENGTH(&amp;amp;DIR);&lt;BR /&gt;
%IF %qSUBSTR(&amp;amp;DIR,&amp;amp;J,1)=&amp;amp;DLM %THEN %DO;&lt;BR /&gt;
%LET COUNT=%EVAL(&amp;amp;COUNT+1);&lt;BR /&gt;
%END; %END;&lt;BR /&gt;
&lt;BR /&gt;
%LET STARTINDEX = 1;&lt;BR /&gt;
%DO I=1 %TO &amp;amp;COUNT;&lt;BR /&gt;
&lt;BR /&gt;
%LET SLASHINDEX = %INDEX(&amp;amp;DIR,&amp;amp;DLM);&lt;BR /&gt;
%LET WORD = %SUBSTR(&amp;amp;DIR,&amp;amp;STARTINDEX,&amp;amp;SLASHINDEX-1);&lt;BR /&gt;
%LET DIR = %SUBSTR(&amp;amp;DIR,&amp;amp;SLASHINDEX+1);&lt;BR /&gt;
%LET STARTINDEX = &amp;amp;SLASHINDEX + 1;&lt;BR /&gt;
&lt;BR /&gt;
%LET LNEW=&amp;amp;WORD;&lt;BR /&gt;
&lt;BR /&gt;
PUT "mkdir "&amp;amp;lnew"";&lt;BR /&gt;
PUT "cd "&amp;amp;lnew"";&lt;BR /&gt;
%END;&lt;BR /&gt;
&lt;BR /&gt;
%LET WORD = &amp;amp;DIR;&lt;BR /&gt;
%LET LNEW=&amp;amp;WORD;&lt;BR /&gt;
PUT "mkdir "&amp;amp;lnew"";&lt;BR /&gt;
PUT "cd "&amp;amp;lnew"";&lt;BR /&gt;
%mend; &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
&lt;BR /&gt;
 OPTIONS MPRINT;&lt;BR /&gt;
 OPTIONS SYMBOLGEN;&lt;BR /&gt;
 OPTIONS MLOGIC;&lt;BR /&gt;
   file ftpcmds pad lrecl=80;&lt;BR /&gt;
   put "user "&amp;amp;userid" "&amp;amp;ftppwd"";&lt;BR /&gt;
   put "verbose";&lt;BR /&gt;
   put "trace";&lt;BR /&gt;
   put "&amp;amp;xfermode";&lt;BR /&gt;
   put "cd "&amp;amp;homedir"";&lt;BR /&gt;
   put "lcd "&amp;amp;localdir"";&lt;BR /&gt;
   call execute('%MD('||&amp;amp;destdir||');');&lt;BR /&gt;
   &lt;BR /&gt;
   /* uncomment the appropriate line below */&lt;BR /&gt;
   put "prompt"; /* used for MPUT and MGET commands */&lt;BR /&gt;
   put "mput SASFTP1.txt SASFTP2.txt";&lt;BR /&gt;
&lt;BR /&gt;
   put "quit";&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
/* We built the control file for ftp, now run it */&lt;BR /&gt;
&lt;BR /&gt;
filename doftp pipe %unquote(%str(%')ftp -n -s:"&amp;amp;ftpcmds" &amp;amp;host%str(%'));&lt;BR /&gt;
data _null_;&lt;BR /&gt;
infile doftp;&lt;BR /&gt;
input;&lt;BR /&gt;
put _infile_;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
----------------------------------------------------------------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Snippet from my log file is &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
---------------------------------------------------------------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
MPRINT(MD):   PUT "mkdir "test1"";&lt;BR /&gt;
SYMBOLGEN:  Macro variable LNEW resolves to test1&lt;BR /&gt;
MPRINT(MD):   PUT "cd "test1"";&lt;BR /&gt;
MLOGIC(MD):  %DO loop index variable I is now 2; loop will not iterate again.&lt;BR /&gt;
MLOGIC(MD):  %LET (variable name is WORD)&lt;BR /&gt;
SYMBOLGEN:  Macro variable DIR resolves to test2&lt;BR /&gt;
MLOGIC(MD):  %LET (variable name is LNEW)&lt;BR /&gt;
SYMBOLGEN:  Macro variable WORD resolves to test2&lt;BR /&gt;
SYMBOLGEN:  Macro variable LNEW resolves to test2&lt;BR /&gt;
MPRINT(MD):   PUT "mkdir "test2"";&lt;BR /&gt;
SYMBOLGEN:  Macro variable LNEW resolves to test2&lt;BR /&gt;
MPRINT(MD):   PUT "cd "test2"";&lt;BR /&gt;
MLOGIC(MD):  Ending execution.&lt;BR /&gt;
NOTE: 9 records were written to the file FTPCMDS.&lt;BR /&gt;
      The minimum record length was 80.&lt;BR /&gt;
      The maximum record length was 80.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: CALL EXECUTE generated line.&lt;BR /&gt;
NOTE: Line generated by the CALL EXECUTE routine.&lt;BR /&gt;
1         + PUT "mkdir "test1"";&lt;BR /&gt;
            ___&lt;BR /&gt;
            180&lt;BR /&gt;
&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Line generated by the CALL EXECUTE routine.&lt;BR /&gt;
1         +                      PUT "cd "test1"";&lt;BR /&gt;
                                 ___&lt;BR /&gt;
                                 180&lt;BR /&gt;
&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Line generated by the CALL EXECUTE routine.&lt;BR /&gt;
1         +                                        PUT "mkdir "test2"";&lt;BR /&gt;
                                                   ___&lt;BR /&gt;
                                                   180&lt;BR /&gt;
&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Line generated by the CALL EXECUTE routine.&lt;BR /&gt;
1         +                                                             PUT "cd "test2"";&lt;BR /&gt;
                                                                        ___&lt;BR /&gt;
                                                                        180&lt;BR /&gt;
&amp;#12;5                                                          The SAS System                          09:28 Tuesday, September 15, 2009&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
---------------------------------------------------------------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
Any ideas what the issue is?  &lt;BR /&gt;
&lt;BR /&gt;
Appreciate any quick help on this.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks &amp;amp; Regards,&lt;BR /&gt;
Neel</description>
    <pubDate>Tue, 15 Sep 2009 16:45:11 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-09-15T16:45:11Z</dc:date>
    <item>
      <title>Macro error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71051#M20500</link>
      <description>I have the following macro MD – &lt;BR /&gt;
&lt;BR /&gt;
-----------------------------------------------------------------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
%macro MD(DIR);&lt;BR /&gt;
&lt;BR /&gt;
%LET COUNT=0;&lt;BR /&gt;
&lt;BR /&gt;
 %LET DLM=\;&lt;BR /&gt;
&lt;BR /&gt;
%IF %SUBSTR(&amp;amp;DIR,%LENGTH(&amp;amp;DIR),1) NE &amp;amp;DLM %THEN %DO;&lt;BR /&gt;
&lt;BR /&gt;
%LET DIR=&amp;amp;DIR&amp;amp;DLM;&lt;BR /&gt;
&lt;BR /&gt;
%END;&lt;BR /&gt;
&lt;BR /&gt;
%DO J=1 %TO %LENGTH(&amp;amp;DIR);&lt;BR /&gt;
&lt;BR /&gt;
%IF %SUBSTR(&amp;amp;DIR,&amp;amp;J,1)=&amp;amp;DLM %THEN %DO;&lt;BR /&gt;
&lt;BR /&gt;
%LET COUNT=%EVAL(&amp;amp;COUNT+1);&lt;BR /&gt;
&lt;BR /&gt;
%END; %END;&lt;BR /&gt;
&lt;BR /&gt;
%LET DRIVE=%SUBSTR(&amp;amp;DIR,1,3);&lt;BR /&gt;
&lt;BR /&gt;
%LET LEVEL=&amp;amp;DRIVE;&lt;BR /&gt;
&lt;BR /&gt;
%DO I=2 %TO &amp;amp;COUNT;&lt;BR /&gt;
&lt;BR /&gt;
%LET WORD=%SCAN(&amp;amp;DIR,&amp;amp;I,&amp;amp;DLM);&lt;BR /&gt;
&lt;BR /&gt;
%LET LNEW=&amp;amp;LEVEL&amp;amp;WORD&amp;amp;DLM;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
&lt;BR /&gt;
*rc=filename('newdir',"&amp;amp;lnew");&lt;BR /&gt;
&lt;BR /&gt;
*c=dopen('newdir');&lt;BR /&gt;
&lt;BR /&gt;
*if c=0 then new=dcreate("&amp;amp;word","&amp;amp;level");&lt;BR /&gt;
&lt;BR /&gt;
%PUT "mkdir "&amp;amp;lnew"";&lt;BR /&gt;
&lt;BR /&gt;
%PUT "cd "&amp;amp;lnew"";&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%LET LEVEL=&amp;amp;LNEW;&lt;BR /&gt;
&lt;BR /&gt;
%END;&lt;BR /&gt;
&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
When I invoke it with %MD("C:\test1\test2"); &lt;BR /&gt;
&lt;BR /&gt;
I am getting the following error in the log&lt;BR /&gt;
&lt;BR /&gt;
MLOGIC(MD):  Beginning execution.&lt;BR /&gt;
&lt;BR /&gt;
MLOGIC(MD):  Parameter DIR has value "C:\test1\test2"&lt;BR /&gt;
&lt;BR /&gt;
MLOGIC(MD):  %LET (variable name is COUNT)&lt;BR /&gt;
&lt;BR /&gt;
MLOGIC(MD):  %LET (variable name is DLM)&lt;BR /&gt;
&lt;BR /&gt;
SYMBOLGEN:  Macro variable DIR resolves to "C:\test1\test2"&lt;BR /&gt;
&lt;BR /&gt;
SYMBOLGEN:  Macro variable DIR resolves to "C:\test1\test2"&lt;BR /&gt;
&lt;BR /&gt;
SYMBOLGEN:  Macro variable DLM resolves to \&lt;BR /&gt;
&lt;BR /&gt;
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required.&lt;BR /&gt;
&lt;BR /&gt;
       The condition was: %SUBSTR(&amp;amp;DIR,%LENGTH(&amp;amp;DIR),1) NE &amp;amp;DLM&lt;BR /&gt;
&lt;BR /&gt;
ERROR: The macro MD will stop executing.&lt;BR /&gt;
&lt;BR /&gt;
Appreciate any quick help</description>
      <pubDate>Fri, 11 Sep 2009 22:09:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71051#M20500</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-09-11T22:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71052#M20501</link>
      <description>You have some macro variable matching resolution issue with the &amp;amp;DIR value - particularly where there is special-handling considerations with the back-slash character.&lt;BR /&gt;
&lt;BR /&gt;
Suggest you search the SAS support &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website and consider the Google advanced search argument below for useful reference links:&lt;BR /&gt;
&lt;BR /&gt;
macro variable resolution back slash site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sat, 12 Sep 2009 00:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71052#M20501</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-12T00:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71053#M20502</link>
      <description>If I understand right what you try to achieve: Wouldn't this be a shorter way to do it?&lt;BR /&gt;
&lt;BR /&gt;
%macro MakeDir(DIR);&lt;BR /&gt;
  options noxwait;&lt;BR /&gt;
  x mkdir "&amp;amp;DIR";&lt;BR /&gt;
%mend;&lt;BR /&gt;
%MakeDir(c:\test1\test2\test3);</description>
      <pubDate>Sat, 12 Sep 2009 12:25:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71053#M20502</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-09-12T12:25:30Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71054#M20503</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
loose the double quotes at macro call (as, %MD(C:\test1\test2) ), and it will work just fine.&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Mon, 14 Sep 2009 16:55:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71054#M20503</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-09-14T16:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71055#M20504</link>
      <description>Thanks All for your suggestions. It worked when I used qSUBSTR instead of SUBSTR.&lt;BR /&gt;
&lt;BR /&gt;
I have a problem now writing the commands(ftp) generated by macro to the file&lt;BR /&gt;
&lt;BR /&gt;
Following is my macro code&lt;BR /&gt;
&lt;BR /&gt;
/* Setup libref to execute the ftp command                     */&lt;BR /&gt;
filename ftpcmds "&amp;amp;ftpcmds";&lt;BR /&gt;
&lt;BR /&gt;
%macro MD(DIR);&lt;BR /&gt;
%LET COUNT=0;&lt;BR /&gt;
%LET DLM=\;&lt;BR /&gt;
&lt;BR /&gt;
%DO J=1 %TO %LENGTH(&amp;amp;DIR);&lt;BR /&gt;
%IF %qSUBSTR(&amp;amp;DIR,&amp;amp;J,1)=&amp;amp;DLM %THEN %DO;&lt;BR /&gt;
%LET COUNT=%EVAL(&amp;amp;COUNT+1);&lt;BR /&gt;
%END; %END;&lt;BR /&gt;
&lt;BR /&gt;
%LET STARTINDEX = 1;&lt;BR /&gt;
%DO I=1 %TO &amp;amp;COUNT;&lt;BR /&gt;
&lt;BR /&gt;
%LET SLASHINDEX = %INDEX(&amp;amp;DIR,&amp;amp;DLM);&lt;BR /&gt;
%LET WORD = %SUBSTR(&amp;amp;DIR,&amp;amp;STARTINDEX,&amp;amp;SLASHINDEX-1);&lt;BR /&gt;
%LET DIR = %SUBSTR(&amp;amp;DIR,&amp;amp;SLASHINDEX+1);&lt;BR /&gt;
%LET STARTINDEX = &amp;amp;SLASHINDEX + 1;&lt;BR /&gt;
&lt;BR /&gt;
%LET LNEW=&amp;amp;WORD;&lt;BR /&gt;
&lt;BR /&gt;
%PUT "mkdir "&amp;amp;lnew"";&lt;BR /&gt;
%PUT "cd "&amp;amp;lnew"";&lt;BR /&gt;
%END;&lt;BR /&gt;
&lt;BR /&gt;
%LET WORD = &amp;amp;DIR;&lt;BR /&gt;
%LET LNEW=&amp;amp;WORD;&lt;BR /&gt;
%PUT "mkdir "&amp;amp;lnew"";&lt;BR /&gt;
%PUT "cd "&amp;amp;lnew"";&lt;BR /&gt;
%mend; &lt;BR /&gt;
&lt;BR /&gt;
The PUT statements don't seem to be writing to file pointed to by ftpcmds&lt;BR /&gt;
&lt;BR /&gt;
The file statement is in the data segment from where the macro is invoked&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
&lt;BR /&gt;
 OPTIONS MPRINT;&lt;BR /&gt;
 OPTIONS SYMBOLGEN;&lt;BR /&gt;
 OPTIONS MLOGIC;&lt;BR /&gt;
   file ftpcmds pad lrecl=80;&lt;BR /&gt;
&lt;BR /&gt;
....&lt;BR /&gt;
....&lt;BR /&gt;
&lt;BR /&gt;
   %MD(&amp;amp;destdir); /* destDir is set to test1/test2 */&lt;BR /&gt;
&lt;BR /&gt;
...&lt;BR /&gt;
....&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Any idea why the put statements don't write to the file pointed to by ftpcmds?&lt;BR /&gt;
&lt;BR /&gt;
Thanks &amp;amp; Regards,&lt;BR /&gt;
Neel</description>
      <pubDate>Mon, 14 Sep 2009 21:45:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71055#M20504</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-09-14T21:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71056#M20505</link>
      <description>The %PUT and PUT statements are very different.  You need to use PUT statements to write to a sequential file.  You may need to look at using FPUT as well.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 14 Sep 2009 22:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71056#M20505</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-14T22:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71057#M20506</link>
      <description>Thanks Scott!&lt;BR /&gt;
&lt;BR /&gt;
I changed the code to use PUT statement instead. But I'm getting some error in the log file indicating the PUT used in the macro is not used in the right context.&lt;BR /&gt;
&lt;BR /&gt;
Below is my code fragment containing the macro and the macro invocation block...&lt;BR /&gt;
&lt;BR /&gt;
------------------------------------------------------------------------------------------------&lt;BR /&gt;
/* Setup libref to execute the ftp command                     */&lt;BR /&gt;
filename ftpcmds "&amp;amp;ftpcmds";&lt;BR /&gt;
&lt;BR /&gt;
%macro MD(DIR);&lt;BR /&gt;
%LET COUNT=0;&lt;BR /&gt;
%LET DLM=\;&lt;BR /&gt;
&lt;BR /&gt;
%DO J=1 %TO %LENGTH(&amp;amp;DIR);&lt;BR /&gt;
%IF %qSUBSTR(&amp;amp;DIR,&amp;amp;J,1)=&amp;amp;DLM %THEN %DO;&lt;BR /&gt;
%LET COUNT=%EVAL(&amp;amp;COUNT+1);&lt;BR /&gt;
%END; %END;&lt;BR /&gt;
&lt;BR /&gt;
%LET STARTINDEX = 1;&lt;BR /&gt;
%DO I=1 %TO &amp;amp;COUNT;&lt;BR /&gt;
&lt;BR /&gt;
%LET SLASHINDEX = %INDEX(&amp;amp;DIR,&amp;amp;DLM);&lt;BR /&gt;
%LET WORD = %SUBSTR(&amp;amp;DIR,&amp;amp;STARTINDEX,&amp;amp;SLASHINDEX-1);&lt;BR /&gt;
%LET DIR = %SUBSTR(&amp;amp;DIR,&amp;amp;SLASHINDEX+1);&lt;BR /&gt;
%LET STARTINDEX = &amp;amp;SLASHINDEX + 1;&lt;BR /&gt;
&lt;BR /&gt;
%LET LNEW=&amp;amp;WORD;&lt;BR /&gt;
&lt;BR /&gt;
PUT "mkdir "&amp;amp;lnew"";&lt;BR /&gt;
PUT "cd "&amp;amp;lnew"";&lt;BR /&gt;
%END;&lt;BR /&gt;
&lt;BR /&gt;
%LET WORD = &amp;amp;DIR;&lt;BR /&gt;
%LET LNEW=&amp;amp;WORD;&lt;BR /&gt;
PUT "mkdir "&amp;amp;lnew"";&lt;BR /&gt;
PUT "cd "&amp;amp;lnew"";&lt;BR /&gt;
%mend; &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
&lt;BR /&gt;
 OPTIONS MPRINT;&lt;BR /&gt;
 OPTIONS SYMBOLGEN;&lt;BR /&gt;
 OPTIONS MLOGIC;&lt;BR /&gt;
   file ftpcmds pad lrecl=80;&lt;BR /&gt;
   put "user "&amp;amp;userid" "&amp;amp;ftppwd"";&lt;BR /&gt;
   put "verbose";&lt;BR /&gt;
   put "trace";&lt;BR /&gt;
   put "&amp;amp;xfermode";&lt;BR /&gt;
   put "cd "&amp;amp;homedir"";&lt;BR /&gt;
   put "lcd "&amp;amp;localdir"";&lt;BR /&gt;
   call execute('%MD('||&amp;amp;destdir||');');&lt;BR /&gt;
   &lt;BR /&gt;
   /* uncomment the appropriate line below */&lt;BR /&gt;
   put "prompt"; /* used for MPUT and MGET commands */&lt;BR /&gt;
   put "mput SASFTP1.txt SASFTP2.txt";&lt;BR /&gt;
&lt;BR /&gt;
   put "quit";&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
/* We built the control file for ftp, now run it */&lt;BR /&gt;
&lt;BR /&gt;
filename doftp pipe %unquote(%str(%')ftp -n -s:"&amp;amp;ftpcmds" &amp;amp;host%str(%'));&lt;BR /&gt;
data _null_;&lt;BR /&gt;
infile doftp;&lt;BR /&gt;
input;&lt;BR /&gt;
put _infile_;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
----------------------------------------------------------------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Snippet from my log file is &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
---------------------------------------------------------------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
MPRINT(MD):   PUT "mkdir "test1"";&lt;BR /&gt;
SYMBOLGEN:  Macro variable LNEW resolves to test1&lt;BR /&gt;
MPRINT(MD):   PUT "cd "test1"";&lt;BR /&gt;
MLOGIC(MD):  %DO loop index variable I is now 2; loop will not iterate again.&lt;BR /&gt;
MLOGIC(MD):  %LET (variable name is WORD)&lt;BR /&gt;
SYMBOLGEN:  Macro variable DIR resolves to test2&lt;BR /&gt;
MLOGIC(MD):  %LET (variable name is LNEW)&lt;BR /&gt;
SYMBOLGEN:  Macro variable WORD resolves to test2&lt;BR /&gt;
SYMBOLGEN:  Macro variable LNEW resolves to test2&lt;BR /&gt;
MPRINT(MD):   PUT "mkdir "test2"";&lt;BR /&gt;
SYMBOLGEN:  Macro variable LNEW resolves to test2&lt;BR /&gt;
MPRINT(MD):   PUT "cd "test2"";&lt;BR /&gt;
MLOGIC(MD):  Ending execution.&lt;BR /&gt;
NOTE: 9 records were written to the file FTPCMDS.&lt;BR /&gt;
      The minimum record length was 80.&lt;BR /&gt;
      The maximum record length was 80.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: CALL EXECUTE generated line.&lt;BR /&gt;
NOTE: Line generated by the CALL EXECUTE routine.&lt;BR /&gt;
1         + PUT "mkdir "test1"";&lt;BR /&gt;
            ___&lt;BR /&gt;
            180&lt;BR /&gt;
&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Line generated by the CALL EXECUTE routine.&lt;BR /&gt;
1         +                      PUT "cd "test1"";&lt;BR /&gt;
                                 ___&lt;BR /&gt;
                                 180&lt;BR /&gt;
&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Line generated by the CALL EXECUTE routine.&lt;BR /&gt;
1         +                                        PUT "mkdir "test2"";&lt;BR /&gt;
                                                   ___&lt;BR /&gt;
                                                   180&lt;BR /&gt;
&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Line generated by the CALL EXECUTE routine.&lt;BR /&gt;
1         +                                                             PUT "cd "test2"";&lt;BR /&gt;
                                                                        ___&lt;BR /&gt;
                                                                        180&lt;BR /&gt;
&amp;#12;5                                                          The SAS System                          09:28 Tuesday, September 15, 2009&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
---------------------------------------------------------------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
Any ideas what the issue is?  &lt;BR /&gt;
&lt;BR /&gt;
Appreciate any quick help on this.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks &amp;amp; Regards,&lt;BR /&gt;
Neel</description>
      <pubDate>Tue, 15 Sep 2009 16:45:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71057#M20506</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-09-15T16:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71058#M20507</link>
      <description>The diagnostic is correct - your PUT code is outside the DATA step.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 15 Sep 2009 16:55:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71058#M20507</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-15T16:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71059#M20508</link>
      <description>Thanks Scott!&lt;BR /&gt;
&lt;BR /&gt;
Any idea how to achieve what I'm doing without this issue? I want to write to the file from data segment as well as from inside the macro.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks &amp;amp; Regards,&lt;BR /&gt;
Neel</description>
      <pubDate>Tue, 15 Sep 2009 17:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71059#M20508</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-09-15T17:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71060#M20509</link>
      <description>Not really - [here's one person's opinion] you need to work through the development (and eventually support) of the code yourself - how long has this thread been going, since you needed a "quick reply"?  You need to figure out what it is you want to accomplish, state it clearly, and take the pieces of your various program code you have shared and come up with a working solution, ideally one that you can own and support going forward.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 15 Sep 2009 17:38:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-error/m-p/71060#M20509</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-15T17:38:20Z</dc:date>
    </item>
  </channel>
</rss>

