<?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: Calling a macro with return value inside datastep in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-with-return-value-inside-datastep/m-p/386270#M92483</link>
    <description>&lt;P&gt;As I mentioned above, there is no value in this code. &amp;nbsp;All you are doing is fighting the software when a simple format will do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%Macro Set_nestedval2(TaskID,Status,Section,DSNameP,DSVarP,DSVarP1); 
  Data dm;
    &amp;amp;DSVarP="%location(type=Train)";  
  Run; 
%mend; 

%macro location(type,location=); 
  %if &amp;amp;type.=Airplane %then %let location=Airport; 
  %if &amp;amp;type.=Train %then %let location=Railway_Station; 
  &amp;amp;location. 
%mend location; 

options mprint symbolgen mlogic;
%Set_nestedval2(1,2,3,DM,Entity_name,);&lt;/PRE&gt;
&lt;P&gt;It works, but I really advise against it.&lt;/P&gt;</description>
    <pubDate>Tue, 08 Aug 2017 14:08:10 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-08-08T14:08:10Z</dc:date>
    <item>
      <title>Calling a macro with return value inside datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-with-return-value-inside-datastep/m-p/386254#M92477</link>
      <description>Folks, I have a problem regarding calling a macro from data step. This data step is inside another macro. But fundamentally , it is not possible to get macro value in ‘data step’, although some alternate like ‘call execute’ can be used. But I am not able to get it done. I have below code which is not working and making data variable set empty instead of returning value. Is there any alternative to achieve so ? %Macro Set_nestedval2(TaskID,Status,Section,DSNameP,DSVarP,DSVarP1); /*%let location_1=%location('Train'); */ Data &amp;amp;DSNameP; Set &amp;amp;DSNameP ; &amp;amp;DSVarP=call execute('%nrstr(%location(type=Train));'); /* &amp;amp;DSVarP=&amp;amp; location; */ Run; %put &amp;amp;location_1; %mend; %macro location(type,location=); %if &amp;amp;type='Airplane' %then %let location=Airport; %if &amp;amp;type='Train' %then %let location=Railway_Station; /*%put type is &amp;amp;type.; */ &amp;amp;location; /* this line is effectively the "return value" */ %mend location; %Set_nestedval2(1,2,3,’DM’,’Entity_name’,’’); Thanks,</description>
      <pubDate>Tue, 08 Aug 2017 13:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-with-return-value-inside-datastep/m-p/386254#M92477</guid>
      <dc:creator>Piku</dc:creator>
      <dc:date>2017-08-08T13:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro with return value inside datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-with-return-value-inside-datastep/m-p/386261#M92478</link>
      <description>&lt;P&gt;First of all, use proper code formatting and a code window ({i} or "little running man" button) for posting code. This spaghetti-code is an eyesore.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can't insert code from a dynamically called macro back into the datastep. The datastep is compiled and cannot be changed once it starts running.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the purpose of this honorable mention for the Obfuscated SAS Code Contest?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 13:49:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-with-return-value-inside-datastep/m-p/386261#M92478</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-08T13:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro with return value inside datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-with-return-value-inside-datastep/m-p/386262#M92479</link>
      <description>&lt;P&gt;What is it your trying to achieve? &amp;nbsp;Follow the guidance by the post button:&lt;/P&gt;
&lt;P&gt;Post example test data, in the form of a datastep, using the code window - its the {i}.&lt;/P&gt;
&lt;P&gt;Post what you want out at the end.&lt;/P&gt;
&lt;P&gt;Post any logs or logic which may help explain. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After parsing the unformatted text you provide below, I don't see the point in any of the code. &amp;nbsp;Why not just format the given variable and avoid all this unecessary obfuscation? &amp;nbsp;I.e. have a format type where Airplane=Airport,... and then put type into a new variable with that format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To demonstrate the code window (again the {i} above the post are):&lt;/P&gt;
&lt;PRE&gt;%Macro Set_nestedval2(TaskID,Status,Section,DSNameP,DSVarP,DSVarP1); 
/*%let location_1=%location('Train'); */ 
  Data &amp;amp;DSNameP; 
    Set &amp;amp;DSNameP ; 
    &amp;amp;DSVarP=call execute('%nrstr(%location(type=Train));'); 
    /* &amp;amp;DSVarP=&amp;amp; location; */ 
  Run; 
  %put &amp;amp;location_1; 
%mend; 

%macro location(type,location=); 
  %if &amp;amp;type='Airplane' %then %let location=Airport; 
  %if &amp;amp;type='Train' %then %let location=Railway_Station; 
  /*%put type is &amp;amp;type.; */ &amp;amp;location; /* this line is effectively the "return value" */ 
%mend location; 
%Set_nestedval2(1,2,3,’DM’,’Entity_name’,’’);;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Aug 2017 13:49:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-with-return-value-inside-datastep/m-p/386262#M92479</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-08-08T13:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro with return value inside datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-with-return-value-inside-datastep/m-p/386264#M92480</link>
      <description>&lt;P&gt;You got a lot of the pieces right.&amp;nbsp; First, the small piece:&amp;nbsp; you do have an extra semicolon here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;location;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The %LOCATION macro should return &amp;amp;location without a semicolon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, it's not clear what value you want to assign in your DATA step.&amp;nbsp; Do you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;DSVarP = Railway_Station;&lt;/P&gt;
&lt;P&gt;&amp;amp;DSVarP = "Railway_Station";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using the version with the quotes, you would simply use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;DSVarP = "%location('Train')";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remove the double quotes if you don't need them.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 13:57:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-with-return-value-inside-datastep/m-p/386264#M92480</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-08-08T13:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro with return value inside datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-with-return-value-inside-datastep/m-p/386267#M92482</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;Reposting the simple modified code.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;Here what I want is that datastep in first macro named 'Set_nestedval2' must be able to fetch the value returning from second macro ‘location’. And this location returned must be set as value in one of the column of above ‘dm’.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would like to mention that without outside datastep, I am able to get the returning value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%Macro Set_nestedval2(TaskID,Status,Section,DSNameP,DSVarP,DSVarP1); &lt;BR /&gt;  Data dm;  
    &amp;amp;DSVarP=call execute('%nrstr(%location(type=Train));');  
  Run; 
%mend; 
&lt;BR /&gt;****** Macro 2 *******
%macro location(type,location=); 
  %if &amp;amp;type='Airplane' %then %let location=Airport; 
  %if &amp;amp;type='Train' %then %let location=Railway_Station; 
&amp;amp;location; 
%mend location; &lt;BR /&gt;&lt;BR /&gt;********* calling parent macro ************
%Set_nestedval2(1,2,3,’DM’,’Entity_name’,’’);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 14:04:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-with-return-value-inside-datastep/m-p/386267#M92482</guid>
      <dc:creator>Piku</dc:creator>
      <dc:date>2017-08-08T14:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro with return value inside datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-with-return-value-inside-datastep/m-p/386270#M92483</link>
      <description>&lt;P&gt;As I mentioned above, there is no value in this code. &amp;nbsp;All you are doing is fighting the software when a simple format will do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%Macro Set_nestedval2(TaskID,Status,Section,DSNameP,DSVarP,DSVarP1); 
  Data dm;
    &amp;amp;DSVarP="%location(type=Train)";  
  Run; 
%mend; 

%macro location(type,location=); 
  %if &amp;amp;type.=Airplane %then %let location=Airport; 
  %if &amp;amp;type.=Train %then %let location=Railway_Station; 
  &amp;amp;location. 
%mend location; 

options mprint symbolgen mlogic;
%Set_nestedval2(1,2,3,DM,Entity_name,);&lt;/PRE&gt;
&lt;P&gt;It works, but I really advise against it.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 14:08:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-with-return-value-inside-datastep/m-p/386270#M92483</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-08-08T14:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro with return value inside datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-with-return-value-inside-datastep/m-p/386272#M92484</link>
      <description>&lt;P&gt;&amp;amp;DSVarP= "%location('Train')"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Above is the solution. Adding double quotes give me the result.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 14:16:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-with-return-value-inside-datastep/m-p/386272#M92484</guid>
      <dc:creator>Piku</dc:creator>
      <dc:date>2017-08-08T14:16:38Z</dc:date>
    </item>
  </channel>
</rss>

