<?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 Create code with SAS Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-code-with-SAS-Macro/m-p/212550#M39263</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have SAS code that returns variables with their bins scores. After that, new variables are created based on their bins score. I want to automate this process.&lt;/P&gt;&lt;P&gt;For example, below is the table that is used to create new variables with suffix "_sc".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="334"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD height="20" width="142"&gt;Variable&lt;/TD&gt;&lt;TD width="64"&gt;Min_Bin&lt;/TD&gt;&lt;TD width="64"&gt;Max_Bin&lt;/TD&gt;&lt;TD width="64"&gt;Score&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;Avg_Balance_last_6M&lt;/TD&gt;&lt;TD align="right"&gt;25&lt;/TD&gt;&lt;TD align="right"&gt;50&lt;/TD&gt;&lt;TD align="right"&gt;0.06&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;Avg_Balance_last_6M&lt;/TD&gt;&lt;TD align="right"&gt;51&lt;/TD&gt;&lt;TD align="right"&gt;75&lt;/TD&gt;&lt;TD align="right"&gt;0.05&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;Avg_Balance_last_6M&lt;/TD&gt;&lt;TD align="right"&gt;76&lt;/TD&gt;&lt;TD align="right"&gt;100&lt;/TD&gt;&lt;TD align="right"&gt;0.07&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;Fee_1_3M&lt;/TD&gt;&lt;TD align="right"&gt;0.005&lt;/TD&gt;&lt;TD align="right"&gt;0.009&lt;/TD&gt;&lt;TD align="right"&gt;0.007&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;Fee_1_3M&lt;/TD&gt;&lt;TD align="right"&gt;0.01&lt;/TD&gt;&lt;TD align="right"&gt;0.03&lt;/TD&gt;&lt;TD align="right"&gt;0.06&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;Fee_1_3M&lt;/TD&gt;&lt;TD align="right"&gt;0.03&lt;/TD&gt;&lt;TD align="right"&gt;0.05&lt;/TD&gt;&lt;TD align="right"&gt;0.02&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;Fee_1_3M&lt;/TD&gt;&lt;TD align="right"&gt;0.05&lt;/TD&gt;&lt;TD align="right"&gt;0.07&lt;/TD&gt;&lt;TD align="right"&gt;0.03&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Manual Code :&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF Avg_Balance_last_6M &amp;gt;= 25 then Avg_Balance_last_6M_sc = 0.06;&lt;/P&gt;&lt;P&gt;IF Avg_Balance_last_6M &amp;gt;= 51 then Avg_Balance_last_6M_sc = 0.05;&lt;/P&gt;&lt;P&gt;IF Avg_Balance_last_6M &amp;gt;= 76 then Avg_Balance_last_6M_sc = 0.07;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF Fee_1_3M &amp;gt;= 0.005 then Fee_1_3M_sc = 0.007;&lt;/P&gt;&lt;P&gt;IF Fee_1_3M &amp;gt;= 0.01 then Fee_1_3M_sc = 0.06;&lt;/P&gt;&lt;P&gt;IF Fee_1_3M &amp;gt;= 0.03 then Fee_1_3M_sc = 0.02;&lt;/P&gt;&lt;P&gt;IF Fee_1_3M &amp;gt;= 0.05 then Fee_1_3M_sc = 0.03;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 10 May 2015 13:29:13 GMT</pubDate>
    <dc:creator>Riya88</dc:creator>
    <dc:date>2015-05-10T13:29:13Z</dc:date>
    <item>
      <title>Create code with SAS Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-code-with-SAS-Macro/m-p/212550#M39263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have SAS code that returns variables with their bins scores. After that, new variables are created based on their bins score. I want to automate this process.&lt;/P&gt;&lt;P&gt;For example, below is the table that is used to create new variables with suffix "_sc".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="334"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD height="20" width="142"&gt;Variable&lt;/TD&gt;&lt;TD width="64"&gt;Min_Bin&lt;/TD&gt;&lt;TD width="64"&gt;Max_Bin&lt;/TD&gt;&lt;TD width="64"&gt;Score&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;Avg_Balance_last_6M&lt;/TD&gt;&lt;TD align="right"&gt;25&lt;/TD&gt;&lt;TD align="right"&gt;50&lt;/TD&gt;&lt;TD align="right"&gt;0.06&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;Avg_Balance_last_6M&lt;/TD&gt;&lt;TD align="right"&gt;51&lt;/TD&gt;&lt;TD align="right"&gt;75&lt;/TD&gt;&lt;TD align="right"&gt;0.05&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;Avg_Balance_last_6M&lt;/TD&gt;&lt;TD align="right"&gt;76&lt;/TD&gt;&lt;TD align="right"&gt;100&lt;/TD&gt;&lt;TD align="right"&gt;0.07&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;Fee_1_3M&lt;/TD&gt;&lt;TD align="right"&gt;0.005&lt;/TD&gt;&lt;TD align="right"&gt;0.009&lt;/TD&gt;&lt;TD align="right"&gt;0.007&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;Fee_1_3M&lt;/TD&gt;&lt;TD align="right"&gt;0.01&lt;/TD&gt;&lt;TD align="right"&gt;0.03&lt;/TD&gt;&lt;TD align="right"&gt;0.06&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;Fee_1_3M&lt;/TD&gt;&lt;TD align="right"&gt;0.03&lt;/TD&gt;&lt;TD align="right"&gt;0.05&lt;/TD&gt;&lt;TD align="right"&gt;0.02&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;Fee_1_3M&lt;/TD&gt;&lt;TD align="right"&gt;0.05&lt;/TD&gt;&lt;TD align="right"&gt;0.07&lt;/TD&gt;&lt;TD align="right"&gt;0.03&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Manual Code :&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF Avg_Balance_last_6M &amp;gt;= 25 then Avg_Balance_last_6M_sc = 0.06;&lt;/P&gt;&lt;P&gt;IF Avg_Balance_last_6M &amp;gt;= 51 then Avg_Balance_last_6M_sc = 0.05;&lt;/P&gt;&lt;P&gt;IF Avg_Balance_last_6M &amp;gt;= 76 then Avg_Balance_last_6M_sc = 0.07;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF Fee_1_3M &amp;gt;= 0.005 then Fee_1_3M_sc = 0.007;&lt;/P&gt;&lt;P&gt;IF Fee_1_3M &amp;gt;= 0.01 then Fee_1_3M_sc = 0.06;&lt;/P&gt;&lt;P&gt;IF Fee_1_3M &amp;gt;= 0.03 then Fee_1_3M_sc = 0.02;&lt;/P&gt;&lt;P&gt;IF Fee_1_3M &amp;gt;= 0.05 then Fee_1_3M_sc = 0.03;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 May 2015 13:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-code-with-SAS-Macro/m-p/212550#M39263</guid>
      <dc:creator>Riya88</dc:creator>
      <dc:date>2015-05-10T13:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: Create code with SAS Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-code-with-SAS-Macro/m-p/212551#M39264</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would be very tempted to use the information in your first table to create custom format or informat with the Min_Bin variable as START, Max_bin as End and Score as Label. Then I could either just use the formatted value of the existing variable or make an informat to create the variables with.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data formatcontrol;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have (rename=(Variable=FMTName); /* if any of the variables end in a numeral then we'll need to address that*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Start= put(Min_bin, best8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End = put(Max_bin,Best8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Label = put (score,z9.7);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc format cntlin=formatcontrol;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then you use the formats such as :&lt;/P&gt;&lt;P&gt;Proc freq data=have;&lt;/P&gt;&lt;P&gt;table Avg_Balance_last_6M Fee_1_3M;&lt;/P&gt;&lt;P&gt;format Avg_Balance_last_6M Avg_Balance_last_6M. Fee_1_3M Fee_1_3M.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or create an informat and then&lt;/P&gt;&lt;P&gt;use Fee_1_3M_sc = input (Fee_1_3M,Fee_1_3M.);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 16:53:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-code-with-SAS-Macro/m-p/212551#M39264</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-05-11T16:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create code with SAS Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-code-with-SAS-Macro/m-p/212552#M39265</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I strongly recommend that you don't do this alone.&amp;nbsp; Find a local senior SAS programmer who can guide you through some of the issues.&amp;nbsp; Based on what you have posted so far, here are two issues that you may want to consider.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. What if a variable name is already 30 characters long?&amp;nbsp; There's won't be room to add "_rc" to the end of it.&amp;nbsp; How should that be handled?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. In an automated system, it is often important to make the code as speedy as possible.&amp;nbsp; The manual code&amp;nbsp; you have posted may run quickly enough, or you may want to speed it up by adding ELSE.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF Avg_Balance_last_6M &amp;gt;= 76 then Avg_Balance_last_6M_sc = 0.07;&lt;/P&gt;&lt;P&gt;else IF Avg_Balance_last_6M &amp;gt;= 51 then Avg_Balance_last_6M_sc = 0.05;&lt;/P&gt;&lt;P&gt;else IF Avg_Balance_last_6M &amp;gt;= 25 then Avg_Balance_last_6M_sc = 0.06;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would judge it extremely likely that a senior programmer would find additional issues and shortcuts, and would definitely recommend that route.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 17:11:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-code-with-SAS-Macro/m-p/212552#M39265</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-05-11T17:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: Create code with SAS Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-code-with-SAS-Macro/m-p/212553#M39266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I recommend using call execute for this:&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote" modifiedtitle="true"&gt;
&lt;P&gt;Riya88 wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I have SAS code that returns variables with their bins scores. After that, new variables are created based on their bins score. I want to automate this process.&lt;/P&gt;
&lt;P&gt;For example, below is the table that is used to create new variables with suffix "_sc".&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="334"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD height="20" style="border: 0px solid black;" width="142"&gt;Variable&lt;/TD&gt;
&lt;TD style="border: 0px solid black;" width="64"&gt;Min_Bin&lt;/TD&gt;
&lt;TD style="border: 0px solid black;" width="64"&gt;Max_Bin&lt;/TD&gt;
&lt;TD style="border: 0px solid black;" width="64"&gt;Score&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="20" style="border: 0px solid black;"&gt;Avg_Balance_last_6M&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;25&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;50&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;0.06&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="20" style="border: 0px solid black;"&gt;Avg_Balance_last_6M&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;51&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;75&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;0.05&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="20" style="border: 0px solid black;"&gt;Avg_Balance_last_6M&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;76&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;100&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;0.07&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="20" style="border: 0px solid black;"&gt;Fee_1_3M&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;0.005&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;0.009&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;0.007&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="20" style="border: 0px solid black;"&gt;Fee_1_3M&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;0.01&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;0.03&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;0.06&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="20" style="border: 0px solid black;"&gt;Fee_1_3M&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;0.03&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;0.05&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;0.02&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="20" style="border: 0px solid black;"&gt;Fee_1_3M&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;0.05&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;0.07&lt;/TD&gt;
&lt;TD align="right" style="border: 0px solid black;"&gt;0.03&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;so make a dataset (rules) from this data. In this example I'm assuming that you are having your original data in dataset "source".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set rules end=last;&lt;/P&gt;&lt;P&gt; if _n_=1 then call execute ('Data source; set source;');&lt;/P&gt;&lt;P&gt;call execute ('if '||strip(variable)||' GE '||strip(min_bin) ||' then '||strip(variable)||'_SC = '||strip(score) ||';');&lt;/P&gt;&lt;P&gt;if last then call execute (' run;');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 May 2015 06:48:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-code-with-SAS-Macro/m-p/212553#M39266</guid>
      <dc:creator>AskoLötjönen</dc:creator>
      <dc:date>2015-05-13T06:48:07Z</dc:date>
    </item>
  </channel>
</rss>

