<?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 variable in Macro started with call execute in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-Macro-started-with-call-execute/m-p/358923#M84376</link>
    <description>&lt;P&gt;How about some more macro....:)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; showName(_name);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Actual name: &amp;amp;_name;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &lt;STRONG&gt;&lt;I&gt;t&lt;/I&gt;&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/* open table */&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; dsid = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(open(sashelp.class));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&amp;amp;dsid) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/* iterate over the rows */&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%while&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(fetch(&amp;amp;dsid)) ne -&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; name = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(getvarc(&amp;amp;dsid,&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(varnum(&amp;amp;dsid,name))));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;showName&lt;/I&gt;&lt;/STRONG&gt;(&amp;amp;name);&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/* close table */&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; _rc = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(close(&amp;amp;dsid));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;t&lt;/I&gt;&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 16 May 2017 06:53:35 GMT</pubDate>
    <dc:creator>FredrikE</dc:creator>
    <dc:date>2017-05-16T06:53:35Z</dc:date>
    <item>
      <title>Macro variable in Macro started with call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-Macro-started-with-call-execute/m-p/358919#M84375</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Hope you can help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with a list of file names - I want to run a macro for each file seperately. I have done it like this:&lt;/P&gt;&lt;PRE&gt;data _null_;
set PHFN038;
call execute('%PHFN038('||"file"||');');
run;&lt;/PRE&gt;&lt;P&gt;Inside the macro I have to divide every file in to four subsets two headers, one body and one footer. The problem is that SAS&amp;nbsp;unfortunately cant run this data null statement "inside" the execute data null statement...&lt;/P&gt;&lt;P&gt;Does anybody have a solution?&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro PHFN038 (file);

filename PHFN038 "&amp;amp;FISpath./&amp;amp;file.";

data import;
infile PHFN038 truncover;
input Data $ 1-1768;
run;

data header1;
set import (firstobs=1 obs=1);
format data01 $9. date ddmmyyd10. data03 $6. data04 $1768.;
data01=substr(Data,1,9);
date=input(substr(Data,10,8),yymmdd8.);
data03=substr(Data,19,6);
data04=substr(Data,25);
run;
data header2;
set import (firstobs=2 obs=2);
format data01 $33. date ddmmyyd10. data03 $1768.;
data01=substr(Data,1,33);
date=input(substr(Data,34,8),yymmdd8.);
data03=substr(Data,42);
run;

%let _end=0;
data _null_;
set import;
nobs=_n_;
call symput('_end',nobs);
call symput('_end_b',nobs-1);
run;
%put &amp;amp;_end;


data body;
set import (firstobs=3 obs=&amp;amp;_end_b.);
format cod_tran $2. data02 $2. corp $2. key_num_acct $16. cod_rsn $2. data06 $30. date ddmmyyd10. data08 13. amount commax12.2 currency $3. data11 $108. data12 11. data13 $1768.;
cod_tran=substr(Data,1,2);
data02=substr(Data,3,2);
corp=substr(Data,5,2);
key_num_acct=substr(Data,7,16);
cod_rsn=substr(Data,29,2);
data06=substr(Data,31,30);
date=input(substr(Data,61,8),yymmdd8.);
data08=input(substr(Data,69,13),13.);
amount=input(substr(Data,82,12),12.)/100;
currency=substr(Data,94,3);
data11=substr(Data,97,108);
data12=input(substr(Data,205,11),11.);
data13=substr(Data,216);
run;

data footer;
set import (firstobs=&amp;amp;_end. obs=&amp;amp;_end.);
format data01 $3. count 6. data03 $34. amount commax12.2 data04 $1768.;
data01=substr(Data,1,3);
count=input(substr(Data,4,6),6.);
data03=substr(Data,10,34);
amount=input(substr(Data,44,12),12.)/100;
data04=substr(Data,56);
run;&lt;/PRE&gt;&lt;P&gt;Can I change somthing with:&amp;nbsp;(firstobs=3 obs=&amp;amp;_end_b.)?&lt;BR /&gt;Can I find the last obs some way else?&lt;/P&gt;&lt;P&gt;Or can I call the macro for each line without a data null statement??&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 05:49:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-Macro-started-with-call-execute/m-p/358919#M84375</guid>
      <dc:creator>niby</dc:creator>
      <dc:date>2017-05-16T05:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable in Macro started with call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-Macro-started-with-call-execute/m-p/358923#M84376</link>
      <description>&lt;P&gt;How about some more macro....:)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; showName(_name);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Actual name: &amp;amp;_name;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &lt;STRONG&gt;&lt;I&gt;t&lt;/I&gt;&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/* open table */&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; dsid = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(open(sashelp.class));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&amp;amp;dsid) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/* iterate over the rows */&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%while&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(fetch(&amp;amp;dsid)) ne -&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; name = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(getvarc(&amp;amp;dsid,&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(varnum(&amp;amp;dsid,name))));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;showName&lt;/I&gt;&lt;/STRONG&gt;(&amp;amp;name);&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/* close table */&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; _rc = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(close(&amp;amp;dsid));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;t&lt;/I&gt;&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 06:53:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-Macro-started-with-call-execute/m-p/358923#M84376</guid>
      <dc:creator>FredrikE</dc:creator>
      <dc:date>2017-05-16T06:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable in Macro started with call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-Macro-started-with-call-execute/m-p/358925#M84377</link>
      <description>&lt;P&gt;Well for starters your CALL EXECUTE step looks like it should be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set PHFN038;
call execute('%PHFN038('||file||');');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The FILE variable name must not be in quotes otherwise SAS will treat it as the text string "FILE".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This won't necessarily fix all your problems but it might get you a step closer.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 06:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-Macro-started-with-call-execute/m-p/358925#M84377</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2017-05-16T06:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable in Macro started with call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-Macro-started-with-call-execute/m-p/358929#M84378</link>
      <description>&lt;P&gt;When you call a macro with call execute from a data step, all macro statements in the macro are executed immediately, while all data or procedure steps are delayed until the calling data step finishes.&lt;/P&gt;
&lt;P&gt;So, instead of&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _end=0;
data _null_;
set import;
nobs=_n_;
call symput('_end',nobs);
call symput('_end_b',nobs-1);
run;
%put &amp;amp;_end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'd try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symput('_end',put(nobs),best.);
call symput('_end_b',put(nobs-1,best.));
put nobs;
set import nobs=nobs;
stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 May 2017 07:12:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-Macro-started-with-call-execute/m-p/358929#M84378</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-16T07:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable in Macro started with call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-Macro-started-with-call-execute/m-p/358957#M84383</link>
      <description>&lt;P&gt;What does your data look like, its just seems to be an awful faff splitting thngs up, multiple reads, mulitple files etc. &amp;nbsp;Sure there isn't a simpler method?&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 09:25:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-Macro-started-with-call-execute/m-p/358957#M84383</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-16T09:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable in Macro started with call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-Macro-started-with-call-execute/m-p/358964#M84387</link>
      <description>&lt;P&gt;My data have to be divided into several datasets due to the further processing. It is possible that it can be done easier - but i am not that experienced. Do you have an idea?&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 10:14:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-Macro-started-with-call-execute/m-p/358964#M84387</guid>
      <dc:creator>niby</dc:creator>
      <dc:date>2017-05-16T10:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable in Macro started with call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-Macro-started-with-call-execute/m-p/358968#M84390</link>
      <description>&lt;P&gt;Given that you have solved so much of the problem with one approach, a slight modification should overcome the problems:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;call execute(&lt;FONT color="#008000"&gt;'%nrstr(&lt;/FONT&gt;%PHFN038('|| strip(file) ||')'&lt;FONT color="#008000"&gt;)'&lt;/FONT&gt;);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As was pointed out by other posters, the variable name FILE should not be in quotes, and you need to delay execution of %phfn038 until the DATA step finishes, in order to delay executing the %LET statement within. &amp;nbsp;A small note: &amp;nbsp;semicolon are not needed to execute a macro so one semicolon was removed on purpose.&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 10:41:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-Macro-started-with-call-execute/m-p/358968#M84390</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-05-16T10:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable in Macro started with call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-Macro-started-with-call-execute/m-p/358975#M84392</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;My data have to be divided into several datasets due to the further processing"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Sounds like your whole process is a bit overcomplicated then.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 11:36:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-Macro-started-with-call-execute/m-p/358975#M84392</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-16T11:36:54Z</dc:date>
    </item>
  </channel>
</rss>

