<?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 macro function to use in data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-function-to-use-in-data-step/m-p/691379#M210419</link>
    <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a macro function that I can use in a data step.&amp;nbsp;&lt;/P&gt;&lt;P&gt;it checks the value of variable1 (langa), which in the tables I use always is a char variable ('1','2').&amp;nbsp;&lt;/P&gt;&lt;P&gt;if the value is = '2' then the outcome of the function should be a concatenation of 'OPTN_' and whatever value is in variable2(date_). if not, then it should be 'OPTF_'||var2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is what I have so far (I used do steps since I plan on adding some stuff there later)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*rsubmit;&lt;BR /&gt;%macro ts_date_nice(langa, date_);&lt;BR /&gt;%if &amp;amp;langa = '2' %then&lt;BR /&gt;%do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%let dn = 'OPTN_'||&amp;amp;date_;&lt;BR /&gt;%end;&lt;BR /&gt;%else&lt;BR /&gt;%do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%let dn = 'OPTF_'||&amp;amp;date_;&lt;BR /&gt;%end;&lt;BR /&gt;&amp;amp;dn;&lt;BR /&gt;%mend ts_date_nice;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i tried it like this on a test table:&lt;/P&gt;&lt;P&gt;BROLNG&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ACT_PRD&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NLB&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NLC&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data check;&lt;BR /&gt;set testtbl;&lt;BR /&gt;daten = %ts_date_nice (BROLNG,ACT_PRD);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;result of the new variable daten is however&lt;/P&gt;&lt;P&gt;OPTF__NLB&lt;/P&gt;&lt;P&gt;OPTF__NLC&lt;/P&gt;&lt;P&gt;so the concatenation works, but&amp;nbsp;there is something wrong with the if statement?&lt;/P&gt;&lt;P&gt;I have tried without the '' (so just %if &amp;amp;langa = 2) but that didn't change anything. also ran it on other tables, same result.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Oct 2020 20:10:15 GMT</pubDate>
    <dc:creator>KoVa</dc:creator>
    <dc:date>2020-10-13T20:10:15Z</dc:date>
    <item>
      <title>macro function to use in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-to-use-in-data-step/m-p/691379#M210419</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a macro function that I can use in a data step.&amp;nbsp;&lt;/P&gt;&lt;P&gt;it checks the value of variable1 (langa), which in the tables I use always is a char variable ('1','2').&amp;nbsp;&lt;/P&gt;&lt;P&gt;if the value is = '2' then the outcome of the function should be a concatenation of 'OPTN_' and whatever value is in variable2(date_). if not, then it should be 'OPTF_'||var2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is what I have so far (I used do steps since I plan on adding some stuff there later)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*rsubmit;&lt;BR /&gt;%macro ts_date_nice(langa, date_);&lt;BR /&gt;%if &amp;amp;langa = '2' %then&lt;BR /&gt;%do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%let dn = 'OPTN_'||&amp;amp;date_;&lt;BR /&gt;%end;&lt;BR /&gt;%else&lt;BR /&gt;%do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%let dn = 'OPTF_'||&amp;amp;date_;&lt;BR /&gt;%end;&lt;BR /&gt;&amp;amp;dn;&lt;BR /&gt;%mend ts_date_nice;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i tried it like this on a test table:&lt;/P&gt;&lt;P&gt;BROLNG&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ACT_PRD&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NLB&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NLC&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data check;&lt;BR /&gt;set testtbl;&lt;BR /&gt;daten = %ts_date_nice (BROLNG,ACT_PRD);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;result of the new variable daten is however&lt;/P&gt;&lt;P&gt;OPTF__NLB&lt;/P&gt;&lt;P&gt;OPTF__NLC&lt;/P&gt;&lt;P&gt;so the concatenation works, but&amp;nbsp;there is something wrong with the if statement?&lt;/P&gt;&lt;P&gt;I have tried without the '' (so just %if &amp;amp;langa = 2) but that didn't change anything. also ran it on other tables, same result.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2020 20:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-to-use-in-data-step/m-p/691379#M210419</guid>
      <dc:creator>KoVa</dc:creator>
      <dc:date>2020-10-13T20:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: macro function to use in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-to-use-in-data-step/m-p/691397#M210425</link>
      <description>&lt;P&gt;The macro processor is a&amp;nbsp;&lt;EM&gt;code generator&lt;/EM&gt; and does its work&amp;nbsp;&lt;EM&gt;before&lt;/EM&gt; the resulting code is handed off to the base SAS interpreter.&lt;/P&gt;
&lt;P&gt;To do what you want, macro&amp;nbsp;language is useless. What you want is a data step custom function created with PROC FCMP.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2020 20:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-to-use-in-data-step/m-p/691397#M210425</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-13T20:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: macro function to use in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-to-use-in-data-step/m-p/691400#M210428</link>
      <description>thanks!</description>
      <pubDate>Tue, 13 Oct 2020 20:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-to-use-in-data-step/m-p/691400#M210428</guid>
      <dc:creator>KoVa</dc:creator>
      <dc:date>2020-10-13T20:48:39Z</dc:date>
    </item>
  </channel>
</rss>

