<?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: Calculations, creating a new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Calculations-creating-a-new-variable/m-p/132323#M26961</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data new;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set old;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array vars follow nofollow med vac1 vac2 vac3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array vars_pct pct_follow pct_nofollow &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pct_med pct_vac1 pct_vac2 pct_vac3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do over vars;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pct_vars = (vars/total)*100;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;If you have many variables needs to be include in ARRAY elements than let me know i will give you macro for that so that you dont need to type all the variables in array statements...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;-Urvish&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 08 May 2013 05:39:08 GMT</pubDate>
    <dc:creator>UrvishShah</dc:creator>
    <dc:date>2013-05-08T05:39:08Z</dc:date>
    <item>
      <title>Macro: Calculations, creating a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Calculations-creating-a-new-variable/m-p/132321#M26959</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, I want to perform the same calcluation on 10+ variable (ie., need percentage).&lt;/P&gt;&lt;P&gt;How do I create a macro to do this?&amp;nbsp; I copied and modified code from another program so my macro knowledge is minimal as you can tell.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's what I have:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; %macro table (vars=);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %local (vars);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data new;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set old;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array vars {*} &amp;amp;vars;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=dim (vars);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ??= (vars/total)*100;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *want final variable for each to be:&amp;nbsp; pct_follow, pct_nofollow, pct_med, etc);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;%table (vars=follow nofollow med vac1 vac2 vac3);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;Thank you!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG style=": ; color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 May 2013 22:26:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Calculations-creating-a-new-variable/m-p/132321#M26959</guid>
      <dc:creator>jcis7</dc:creator>
      <dc:date>2013-05-07T22:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: Macro: Calculations, creating a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Calculations-creating-a-new-variable/m-p/132322#M26960</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't need a macro to do this.&amp;nbsp; The reason to create a macro would be if you want to do this over and over, for different sets of variables each time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you do need a macro, the first step would be to sketch out what the program would look like for this one data set, without using any macro language.&amp;nbsp; How could you accomplish what you want in this case, but without using macros?&amp;nbsp; That's the starting point for understanding what a macro would look like.&amp;nbsp; In particular, where does TOTAL come from?&amp;nbsp; Is it already part of your data set?&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>Wed, 08 May 2013 00:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Calculations-creating-a-new-variable/m-p/132322#M26960</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-05-08T00:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: Macro: Calculations, creating a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Calculations-creating-a-new-variable/m-p/132323#M26961</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data new;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set old;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array vars follow nofollow med vac1 vac2 vac3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array vars_pct pct_follow pct_nofollow &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pct_med pct_vac1 pct_vac2 pct_vac3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do over vars;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pct_vars = (vars/total)*100;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;If you have many variables needs to be include in ARRAY elements than let me know i will give you macro for that so that you dont need to type all the variables in array statements...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;-Urvish&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 May 2013 05:39:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Calculations-creating-a-new-variable/m-p/132323#M26961</guid>
      <dc:creator>UrvishShah</dc:creator>
      <dc:date>2013-05-08T05:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro: Calculations, creating a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Calculations-creating-a-new-variable/m-p/132324#M26962</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote" modifiedtitle="true"&gt;&lt;/PRE&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote" modifiedtitle="true"&gt;
&lt;P&gt;UrvishShah wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;If you have many variables needs to be include in ARRAY elements than let me know i will give you macro for that so that you dont need to type all the variables in array statements...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;-Urvish&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is a MACRO really needed?&amp;nbsp; I usually use a "SAS Variable List" &lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#p0wphcpsfgx6o7n1sjtqzizp1n39.htm"&gt;http://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#p0wphcpsfgx6o7n1sjtqzizp1n39.htm&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 May 2013 10:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Calculations-creating-a-new-variable/m-p/132324#M26962</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-05-08T10:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Macro: Calculations, creating a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Calculations-creating-a-new-variable/m-p/132325#M26963</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN class="j-post-author "&gt;&lt;STRONG&gt;&lt;A _jive_internal="true" class="jiveTT-hover-user jive-username-link" data-avatarid="1061" data-externalid="" data-presence="null" data-userid="468858" data-username="data_null_%3B" href="https://communities.sas.com/people/data_null_;" id="jive-46885868496311771544803"&gt;data_null_;&lt;/A&gt; Yes Macro is not needed...We can directly refrence the range of variables as ARRAY elements...so simple...Why i opt for macro all the time ???&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author "&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author "&gt;&lt;STRONG&gt;-Urvish&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 May 2013 10:34:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Calculations-creating-a-new-variable/m-p/132325#M26963</guid>
      <dc:creator>UrvishShah</dc:creator>
      <dc:date>2013-05-08T10:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macro: Calculations, creating a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Calculations-creating-a-new-variable/m-p/132326#M26964</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Make a dataset contains "&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;follow nofollow med vac1 vac2 vac3"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;then call execute that macro .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;Ksharp&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 May 2013 14:51:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Calculations-creating-a-new-variable/m-p/132326#M26964</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2013-05-08T14:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro: Calculations, creating a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Calculations-creating-a-new-variable/m-p/132327#M26965</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you everyone!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 May 2013 15:31:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Calculations-creating-a-new-variable/m-p/132327#M26965</guid>
      <dc:creator>jcis7</dc:creator>
      <dc:date>2013-05-08T15:31:55Z</dc:date>
    </item>
  </channel>
</rss>

