<?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 from a data sep in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/calling-a-macro-from-a-data-sep/m-p/128638#M26262</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Don't use a macro, use a format instead. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi30/001-30.pdf" title="http://www2.sas.com/proceedings/sugi30/001-30.pdf"&gt;http://www2.sas.com/proceedings/sugi30/001-30.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc format;&lt;/P&gt;&lt;P&gt;value $ salida_fmt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'ab' = 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'ac' = 2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;campo2=put(campo1, $salida_fmt.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 08 Jul 2013 14:38:52 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2013-07-08T14:38:52Z</dc:date>
    <item>
      <title>calling a macro from a data sep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calling-a-macro-from-a-data-sep/m-p/128636#M26260</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to create a field in a datasets based in the value of another field.&lt;/P&gt;&lt;P&gt;I'm usind a macro to make se assignment of the value. Yo can see the process bellow.&lt;/P&gt;&lt;P&gt;The real macro is not that simplem but I'ms using it to make tests.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I expect that result:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;campo1 campo2&lt;/P&gt;&lt;P&gt;ab&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;ac&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but I get:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;campo1 campo2&lt;/P&gt;&lt;P&gt;ab&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;ac&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not sure if I have any error in the method of calling a macro from a data sets&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anybodt hepl me???, any advice would n greatly apreciatted.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;----&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data prueba;&lt;/P&gt;&lt;P&gt;length campo1 $10.;&lt;/P&gt;&lt;P&gt;campo1 = 'ab';&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;campo1 = 'ac';&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data prueba1;&lt;/P&gt;&lt;P&gt;set prueba;&lt;/P&gt;&lt;P&gt;campo2 = %valor1(campo1);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro valor1(campo);&lt;/P&gt;&lt;P&gt;%if %trim(&amp;amp;campo) = 'ab' %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let salida = 1;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%else %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let salida = 2;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;amp;salida;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jul 2013 13:20:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calling-a-macro-from-a-data-sep/m-p/128636#M26260</guid>
      <dc:creator>juanvg1972</dc:creator>
      <dc:date>2013-07-08T13:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: calling a macro from a data sep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calling-a-macro-from-a-data-sep/m-p/128637#M26261</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why are you mixing data step and macro logic? Can't see any reason for you to use macros from your sample in- and outputs.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jul 2013 14:37:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calling-a-macro-from-a-data-sep/m-p/128637#M26261</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-07-08T14:37:51Z</dc:date>
    </item>
    <item>
      <title>Re: calling a macro from a data sep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calling-a-macro-from-a-data-sep/m-p/128638#M26262</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Don't use a macro, use a format instead. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi30/001-30.pdf" title="http://www2.sas.com/proceedings/sugi30/001-30.pdf"&gt;http://www2.sas.com/proceedings/sugi30/001-30.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc format;&lt;/P&gt;&lt;P&gt;value $ salida_fmt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'ab' = 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'ac' = 2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;campo2=put(campo1, $salida_fmt.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jul 2013 14:38:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calling-a-macro-from-a-data-sep/m-p/128638#M26262</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-07-08T14:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: calling a macro from a data sep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calling-a-macro-from-a-data-sep/m-p/128639#M26263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Macro code generates SAS code to be included in your program for SAS to execute.&amp;nbsp; You cannot use it to test values of dataset variables, just the strings that you have passed it in macro variables.&lt;/P&gt;&lt;P&gt;You might get what you want be having the macro generate the data step code that you need.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%macro valor1(source,target);&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if &amp;amp;source = 'ab' then &amp;amp;target =&amp;nbsp; 1;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;else &amp;amp;target = 2;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data prueba1;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;set prueba;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%valor1(campo1,campo2);&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jul 2013 14:39:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calling-a-macro-from-a-data-sep/m-p/128639#M26263</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-07-08T14:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: calling a macro from a data sep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calling-a-macro-from-a-data-sep/m-p/128640#M26264</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;call execute() is the interface between data step and macro device.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data prueba;
length campo1 $ 10;
campo1 = 'ab';
output;
campo1 = 'ac';
output;
run;

data _null_;
set prueba end=last;
if _n_ eq 1 then call execute('data prueba1;');
call execute('campo1="'||strip(campo1)||'";campo2 = %valor1('||strip(campo1)||');output;');
if last then call execute('run;');
run;
 

%macro valor1(campo);
%if &amp;amp;campo = ab %then %do;
&amp;nbsp;&amp;nbsp;&amp;nbsp; %let salida = 1;
%end;
%else %do;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let salida = 2;
%end;
&amp;amp;salida

%put &amp;amp;salida;
%mend;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jul 2013 15:31:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calling-a-macro-from-a-data-sep/m-p/128640#M26264</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2013-07-08T15:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: calling a macro from a data sep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calling-a-macro-from-a-data-sep/m-p/128641#M26265</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you care about speed ,use resolve() ,resolve() is also the interface between data step and macro device.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data prueba;
length campo1 $ 10;
campo1 = 'ab';
output;
campo1 = 'ac';
output;
run;


%macro valor1(campo);
%if &amp;amp;campo = ab %then %do;
&amp;nbsp;&amp;nbsp;&amp;nbsp; %let salida = 1;
%end;
%else %do;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let salida = 2;
%end;
&amp;amp;salida

%put &amp;amp;salida;
%mend;

data prueba1;
set prueba;
campo2 =resolve( '%valor1('||strip(campo1)||')');
run;
 


 
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jul 2013 01:46:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calling-a-macro-from-a-data-sep/m-p/128641#M26265</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2013-07-09T01:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: calling a macro from a data sep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calling-a-macro-from-a-data-sep/m-p/128642#M26266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your help!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Juan V.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://recursossassoftware.blogspot.com.es/" title="http://recursossassoftware.blogspot.com.es/"&gt;Utilidades, recursos, ejemplos y documentación sobre el software de análisis de datos SAS&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Aug 2013 13:14:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calling-a-macro-from-a-data-sep/m-p/128642#M26266</guid>
      <dc:creator>juanvg1972</dc:creator>
      <dc:date>2013-08-02T13:14:40Z</dc:date>
    </item>
  </channel>
</rss>

