<?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 to automate derived fields. Please Help..Thank You in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192942#M36335</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Am not re-writing it again.&amp;nbsp; If the variables are not the same then you would need to put that information in somehow.&amp;nbsp; You could do that by array for example, or a dataset.&amp;nbsp; There's no coding way of know that 1 = Sales.&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array vals{100} $200. ("sales","...);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute('data want; set have;');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do I=1 to 100;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute('V'||strip(vals{I})||'_amt_32 = sum...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Again though, think about your data differently, you will have further troubles down the line when you try to do anything with this data.&amp;nbsp; Try to get to a stage where your dataset looks like:&lt;/P&gt;&lt;P&gt;section&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; amt_mth_03&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; amt_mth_04 ...&lt;/P&gt;&lt;P&gt;sales&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xyz&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; xyz&lt;/P&gt;&lt;P&gt;rather than separate variables for each&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 03 Dec 2014 16:14:55 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2014-12-03T16:14:55Z</dc:date>
    <item>
      <title>Macro to automate derived fields. Please Help..Thank You</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192939#M36332</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;Hi All,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;I would like to automate the calculation below , I have to create these calculated fields like 100 times as I have 100 variables to analyse, The example below only does it for 5 variables...Your help woul be really much appreciated!!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;Many Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="WIDTH: 640px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD colspan="7" height="20" width="448"&gt;V1_amt_32 = sum(V1_amt_mth_03, V1_amt_mth_02) / min(tenure, 2);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="9" height="20"&gt;V1_amt_432 = sum(V1_amt_mth_04, V1_amt_mth_03, V1_amt_mth_02) / min(tenure, 3);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="10" height="20"&gt;&lt;P&gt;if V1_amt_mth_04 ne . or V1_amt_mth_05 ne . then V1_amt_54 = sum(V1_amt_mth_05, V1_amt_mth_04) / min(tenure, 2);&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="7" height="20"&gt;V2_amt_32 = sum(V2_amt_mth_03, V2_amt_mth_02) / min(tenure, 2);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="9" height="20"&gt;V2_amt_432 = sum(V2_amt_mth_04, V2_amt_mth_03, V2_amt_mth_02) / min(tenure, 3);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="10" height="20"&gt;&lt;P&gt;if V2_amt_mth_04 ne . or V2_amt_mth_05 ne . then V2_amt_54 = sum(V2_amt_mth_05, V2_amt_mth_04) / min(tenure, 2);&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="8" height="20"&gt;V3_units_32 = sum(V3_units_mth_03, V3_units_mth_02) / min(tenure, 2);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="10" height="20"&gt;V3_units_432 = sum(V3_units_mth_04, V3_units_mth_03, V3_units_mth_02) / min(tenure, 3);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="10" height="20"&gt;&lt;P&gt;if V3_units_mth_04 ne . or V3_units_mth_05 ne . then V3_units_54 = sum(V3_units_mth_05, V3_units_mth_04) / min(tenure, 2);&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="6" height="20"&gt;V4_32 = sum(V4_mth_03, V4_mth_02) / min(tenure, 2);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="7" height="20"&gt;V4_432 = sum(V4_mth_04, V4_mth_03, V4_mth_02) / min(tenure, 3);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="10" height="20"&gt;&lt;P&gt;if V4_mth_04 ne . or V4_mth_05 ne . then V4_54 = sum(V4_mth_05, V4_mth_04) / min(tenure, 2);&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="6" height="20"&gt;V5_32 = sum(V5_mth_03, V5_mth_02) / min(tenure, 2);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="7" height="20"&gt;V5_432 = sum(V5_mth_04, V5_mth_03, V5_mth_02) / min(tenure, 3);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="10" height="20"&gt;if V5_mth_04 ne . or V5_mth_05 ne . then V5_54 = sum(V5_mth_05, V5_mth_04) / min(tenure, 2);&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;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 15:18:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192939#M36332</guid>
      <dc:creator>Kanyange</dc:creator>
      <dc:date>2014-12-03T15:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to automate derived fields. Please Help..Thank You</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192940#M36333</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute('data want; set have;');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do I=1 to 100;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute('V'||strip(put(I,best.))||'_amt_32 = sum(V'||strip(put(I,best.))||'_amt_mth_03, V'||strip(put(I,best.))||'_amt_mth_02) / min(tenure, 2); &lt;/P&gt;&lt;P&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; V'||strip(put(I,best.))||'_amt_432 = sum(V'||strip(put(I,best.))||'_amt_mth_04, V'||strip(put(I,best.))||'_amt_mth_03, V'||strip(put(I,best.))||'_amt_mth_02) / min(tenure, 3); &lt;/P&gt;&lt;P&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; if V'||strip(put(I,best.))||'_amt_mth_04 ne . or V'||strip(put(I,best.))||'_amt_mth_05 ne . then V'||strip(put(I,best.))||'_amt_54 = sum(V'||strip(put(I,best.))||'_amt_mth_05, V'||strip(put(I,best.))||'_amt_mth_04) / min(tenure, 2);');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute('run;');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;This will generate your 100 statement datastep replacing I each time.&amp;nbsp; However I would question why you are going in this route at all.&amp;nbsp; Put categories into your data, have a row per category, and then do you calculation, far easier.&amp;nbsp; Alternative learn about arrays, they are built to work on many variables.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 15:27:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192940#M36333</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-12-03T15:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to automate derived fields. Please Help..Thank You</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192941#M36334</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you! Sorry I forgot to mention that te varaibles have different names so V1 is Sales, V2 is Units..etc...so basically the variables are like below&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="828"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD colspan="8" height="20" width="512"&gt;Sales_amt_32 = sum(Sales_amt_mth_03, Sales_amt_mth_02) / min(tenure, 2);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="10" height="20"&gt;Sales_amt_432 = sum(Sales_amt_mth_04, Sales_amt_mth_03, Sales_amt_mth_02) / min(tenure, 3);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="11" height="20"&gt;if Sales_amt_mth_04 ne . or Sales_amt_mth_05 ne . then Sales_amt_54 = sum(Sales_amt_mth_05, Sales_amt_mth_04) / min(tenure, 2);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="8" height="20"&gt;Disc_amt_32 = sum(Disc_amt_mth_03, Disc_amt_mth_02) / min(tenure, 2);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="10" height="20"&gt;Disc_amt_432 = sum(Disc_amt_mth_04, Disc_amt_mth_03, Disc_amt_mth_02) / min(tenure, 3);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="11" height="20"&gt;if Disc_amt_mth_04 ne . or Disc_amt_mth_05 ne . then Disc_amt_54 = sum(Disc_amt_mth_05, Disc_amt_mth_04) / min(tenure, 2);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="7" height="20"&gt;Units_32 = sum(Units_mth_03, Units_mth_02) / min(tenure, 2);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="8" height="20"&gt;Units_432 = sum(Units_mth_04, Units_mth_03, Units_mth_02) / min(tenure, 3);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="11" height="20"&gt;if Units_mth_04 ne . or Units_mth_05 ne . then Units_54 = sum(Units_mth_05, Units_mth_04) / min(tenure, 2);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="6" height="20"&gt;Trips_32 = sum(Trips_mth_03, Trips_mth_02) / min(tenure, 2);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="8" height="20"&gt;Trips_432 = sum(Trips_mth_04, Trips_mth_03, Trips_mth_02) / min(tenure, 3);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="11" height="20"&gt;if Trips_mth_04 ne . or Trips_mth_05 ne . then Trips_54 = sum(Trips_mth_05, Trips_mth_04) / min(tenure, 2);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="6" height="20"&gt;days_32 = sum(days_mth_03, days_mth_02) / min(tenure, 2);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="8" height="20"&gt;days_432 = sum(days_mth_04, days_mth_03, days_mth_02) / min(tenure, 3);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="11" height="20"&gt;if days_mth_04 ne . or days_mth_05 ne . then days_54 = sum(days_mth_05, days_mth_04) / min(tenure, 2);&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 16:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192941#M36334</guid>
      <dc:creator>Kanyange</dc:creator>
      <dc:date>2014-12-03T16:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to automate derived fields. Please Help..Thank You</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192942#M36335</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Am not re-writing it again.&amp;nbsp; If the variables are not the same then you would need to put that information in somehow.&amp;nbsp; You could do that by array for example, or a dataset.&amp;nbsp; There's no coding way of know that 1 = Sales.&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array vals{100} $200. ("sales","...);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute('data want; set have;');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do I=1 to 100;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute('V'||strip(vals{I})||'_amt_32 = sum...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Again though, think about your data differently, you will have further troubles down the line when you try to do anything with this data.&amp;nbsp; Try to get to a stage where your dataset looks like:&lt;/P&gt;&lt;P&gt;section&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; amt_mth_03&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; amt_mth_04 ...&lt;/P&gt;&lt;P&gt;sales&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xyz&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; xyz&lt;/P&gt;&lt;P&gt;rather than separate variables for each&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 16:14:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192942#M36335</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-12-03T16:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to automate derived fields. Please Help..Thank You</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192943#M36336</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;RW9's suggestion about arrays is a good one.&amp;nbsp; If you are looking for an introduction to using macros, this would be a good case to get started.&amp;nbsp; Define a macro that contains the calculations for one variable:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro calculate (varname);&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="WIDTH: 828px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD colspan="7" height="20" rowspan="1" style="border: black 0px solid;"&gt;&lt;P&gt;&amp;amp;varname._32 = sum(&amp;amp;varname._mth_03, &amp;amp;varname._mth_02) / min(tenure, 2);&lt;/P&gt;&lt;P&gt;&amp;amp;varname._432 = sum(&amp;amp;varname._mth_04, &amp;amp;varname._mth_03, &amp;amp;varname._mth_02) / min(tenure, 3);&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="11" height="20" rowspan="1" style="border: black 0px solid;"&gt;&lt;P&gt;if &amp;amp;varname._mth_04 ne . or &amp;amp;varname._mth_05 ne . then&lt;/P&gt;&lt;P&gt;&amp;amp;varname._54 = sum(&amp;amp;varname._mth_05, &amp;amp;varname._mth_04) / min(tenure, 2);&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;%mend calculate;&lt;/P&gt;&lt;P&gt;Then begin the learning process by calling the macro as many times as needed:&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;%calculate (Sales)&lt;/P&gt;&lt;P&gt;%calculate (Disc)&lt;/P&gt;&lt;P&gt;%calculate (Units)&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once it is clear how that works, look for a way to further automate.&amp;nbsp; That would involve writing another macro that uses a list of prefixes to generate the equivalent macro calls, such as:&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;%expand (Sales Disc Units)&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But take it one step at a time, until you are comfortable with writing the code that gets you through that step.&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, 03 Dec 2014 16:23:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192943#M36336</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-12-03T16:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to automate derived fields. Please Help..Thank You</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192944#M36337</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, I get the error below when I run the code..Could you please let me know the problem? Cheers&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GOPTIONS ACCESSIBLE;&lt;BR /&gt;SYMBOLGEN:&amp;nbsp; Macro variable VARNAME resolves to and_mktg_voucher_amt&lt;BR /&gt;15&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %calculate (and_mktg_voucher_amt);&lt;BR /&gt;SYMBOLGEN:&amp;nbsp; Macro variable VARNAME resolves to and_mktg_voucher_amt&lt;BR /&gt;NOTE: Line generated by the macro variable "VARNAME".&lt;BR /&gt;15&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and_mktg_voucher_amt_32&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _______________________&lt;BR /&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 16:54:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192944#M36337</guid>
      <dc:creator>Kanyange</dc:creator>
      <dc:date>2014-12-03T16:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to automate derived fields. Please Help..Thank You</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192945#M36338</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Diagnosis requires a little more information to work with.&amp;nbsp; Please post your macro definition (just to verify that it was properly duplicated) as well as the DATA step that calls the macro.&amp;nbsp; There's probably an easy answer there.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 17:04:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192945#M36338</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-12-03T17:04:09Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to automate derived fields. Please Help..Thank You</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192946#M36339</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry , I have fixed the error &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thanks a lot for your help...What does the %expand macro do?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 17:07:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192946#M36339</guid>
      <dc:creator>Kanyange</dc:creator>
      <dc:date>2014-12-03T17:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to automate derived fields. Please Help..Thank You</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192947#M36340</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The concept of an %expand macro would save a little typing.&amp;nbsp; You would enter:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%expand (Sales Disc Units)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It would convert this to:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%calculate (Sales)&lt;/P&gt;&lt;P&gt;%calculate (Disc)&lt;/P&gt;&lt;P&gt;%Calculate (Units)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But it's not an existing macro ... and takes a little more skill to write than %calculate.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 17:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192947#M36340</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-12-03T17:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to automate derived fields. Please Help..Thank You</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192948#M36341</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another question, is there any other way to write this macro, withouth showing all the name of variables...I wanted to keep non manual as much as I can...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 17:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192948#M36341</guid>
      <dc:creator>Kanyange</dc:creator>
      <dc:date>2014-12-03T17:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to automate derived fields. Please Help..Thank You</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192949#M36342</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, but you would have to have a source that would supply all the names.&amp;nbsp; How would you get the names of the variables?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 17:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192949#M36342</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-12-03T17:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to automate derived fields. Please Help..Thank You</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192950#M36343</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I can get it from a proc contents of a table that I am using! Does it answer your question?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank You&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 22:56:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192950#M36343</guid>
      <dc:creator>Kanyange</dc:creator>
      <dc:date>2014-12-03T22:56:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to automate derived fields. Please Help..Thank You</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192951#M36344</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Seems like you have a lot of DATA coded into the meta data (variable names).&amp;nbsp; If you normalized your data the problem will be much simpler.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 23:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192951#M36344</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2014-12-03T23:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to automate derived fields. Please Help..Thank You</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192952#M36345</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK, taking that approach here are some things you can do.&amp;nbsp; First, get the list of variable names into a macro variable:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc contents data=have noprint out=_contents_ (keep=name type where=(type=1));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;select strip(name) into : list_of_vars separated by ' ' from _contents_;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;list_of_vars;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are other ways to do this, and you may have to tweak the list a bit before running the final SQL.&amp;nbsp; For example, this list contains all the numeric variables and you may have to shorten that to get just the prefixes&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then write a macro that can process each name in the list:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro expand (var_list=);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %local i next_name;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do i=1 %to %sysfunc(countw(&amp;amp;var_list));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let next_name = %scan(&amp;amp;var_list, &amp;amp;i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %calculate (&amp;amp;next_name)&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend expand;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then use the macros in a DATA step:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %expand (var_list=&amp;amp;list_of_names)&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That's the basic outline ... you can tweak it as needed and learn the pieces as you go.&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>Thu, 04 Dec 2014 00:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192952#M36345</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-12-04T00:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to automate derived fields. Please Help..Thank You</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192953#M36346</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much Astounding! Your answer is Outstanding &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I will try this and will let you know how it goes...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2014 01:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-derived-fields-Please-Help-Thank-You/m-p/192953#M36346</guid>
      <dc:creator>Kanyange</dc:creator>
      <dc:date>2014-12-04T01:52:21Z</dc:date>
    </item>
  </channel>
</rss>

