<?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 How to use years in variable names in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-years-in-variable-names-in-macro/m-p/512041#M137868</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this following binary dataset:&lt;/P&gt;&lt;P&gt;a_0405&amp;nbsp; a_0506 a_0607 a_0708... a_n etc&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;Using A_0506 as the base year, how can i instruct SAS to look at future years (i.e. a_0607 a_0708...a_n) and return a 0 if the value of future years is 1?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know if you require more information and i apologise in advance if the question is unclear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;</description>
    <pubDate>Sun, 11 Nov 2018 21:58:12 GMT</pubDate>
    <dc:creator>sae123</dc:creator>
    <dc:date>2018-11-11T21:58:12Z</dc:date>
    <item>
      <title>How to use years in variable names in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-years-in-variable-names-in-macro/m-p/512041#M137868</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this following binary dataset:&lt;/P&gt;&lt;P&gt;a_0405&amp;nbsp; a_0506 a_0607 a_0708... a_n etc&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;Using A_0506 as the base year, how can i instruct SAS to look at future years (i.e. a_0607 a_0708...a_n) and return a 0 if the value of future years is 1?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know if you require more information and i apologise in advance if the question is unclear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;</description>
      <pubDate>Sun, 11 Nov 2018 21:58:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-years-in-variable-names-in-macro/m-p/512041#M137868</guid>
      <dc:creator>sae123</dc:creator>
      <dc:date>2018-11-11T21:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to use years in variable names in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-years-in-variable-names-in-macro/m-p/512043#M137869</link>
      <description>&lt;P&gt;Instead of different months data in different variables it would be much easier to process your data if you transformed your data into rows with a MONTH variable that defines the months and just one variable A to hold the "A" data.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Nov 2018 22:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-years-in-variable-names-in-macro/m-p/512043#M137869</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2018-11-11T22:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to use years in variable names in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-years-in-variable-names-in-macro/m-p/512044#M137870</link>
      <description>&lt;P&gt;Some of this is definitely unclear:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;When should the program return a 0?&amp;nbsp; When ALL future years contain 1, or when ANY future years contain 1?&lt;/LI&gt;
&lt;LI&gt;What should the program return when future years contain something else other than 1?&lt;/LI&gt;
&lt;LI&gt;What is the last year in your data?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;And just to confirm ... it looks like you are asking for the program to add just 1 new variable to your data set.&amp;nbsp; Is that right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are there any other variable names that begin with "a_0" other than these year variables?&lt;/P&gt;</description>
      <pubDate>Sun, 11 Nov 2018 22:24:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-years-in-variable-names-in-macro/m-p/512044#M137870</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-11-11T22:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to use years in variable names in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-years-in-variable-names-in-macro/m-p/512046#M137872</link>
      <description>&lt;P&gt;Hi Astounding,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In response to your questions -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;EM&gt;When should the program return a 0?&amp;nbsp; When ALL future years contain 1, or when ANY future years contain 1?&lt;/EM&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Return a 0 if ANY future years contain 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;EM&gt;What should the program return when future years contain something else other than 1?&lt;/EM&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;All future years for the variable contain either a 0 or 1. If all future years contain 0, then return 1 otherwise return 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;EM&gt;What is the last year in your data?&lt;/EM&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;1617 though i was hoping the macro is capable to identify the latest year (if at all possible)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;And just to confirm ... it looks like you are asking for the program to add just 1 new variable to your data set.&amp;nbsp; Is that right?&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That is correct - if all future years for A_N = 0 then new_variable =1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Are there any other variable names that begin with "a_0" other than these year variables?&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are 1.2m observation/clients with and over 300 variables. However, none of these variables share the same "a_0" name.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The variables represent services and return 1 if the client had used the service for the given year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps to clarify the question!&lt;/P&gt;</description>
      <pubDate>Sun, 11 Nov 2018 22:48:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-years-in-variable-names-in-macro/m-p/512046#M137872</guid>
      <dc:creator>sae123</dc:creator>
      <dc:date>2018-11-11T22:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to use years in variable names in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-years-in-variable-names-in-macro/m-p/512048#M137874</link>
      <description>&lt;P&gt;Good.&amp;nbsp; Believe it or not, that's all necessary information.&amp;nbsp; &amp;nbsp;I hope I understood these responses correctly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;"Return a 0 if ANY future years contain 1"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;"If all future years contain 0, then return 1 otherwise return 0"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's one way to go about it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array yrs {*} a_0: ;&lt;/P&gt;
&lt;P&gt;a_n=1;&lt;/P&gt;
&lt;P&gt;do k=1 to dim(yrs) until (a_n=0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; years = substr(vname(yrs{k}), 3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if years &amp;gt; '0506' and yrs{k}=1 then a_n=0;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop k years;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's untested code, but looks about right.&amp;nbsp; Let me know if you encounter any difficulty with it.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Nov 2018 23:37:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-years-in-variable-names-in-macro/m-p/512048#M137874</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-11-11T23:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to use years in variable names in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-years-in-variable-names-in-macro/m-p/512052#M137875</link>
      <description>&lt;P&gt;Greatly appreciate your help Astounding.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for the stupid question, but just so that i'm clear -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A_N is the variable, where N is the year (0405, 0506...n etc.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm just not entirely sure on what the A_0 is. Can you please clarify? Is this the new variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;</description>
      <pubDate>Mon, 12 Nov 2018 00:02:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-years-in-variable-names-in-macro/m-p/512052#M137875</guid>
      <dc:creator>sae123</dc:creator>
      <dc:date>2018-11-12T00:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to use years in variable names in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-years-in-variable-names-in-macro/m-p/512177#M137915</link>
      <description>&lt;P&gt;A_N is the new variable that flags whether there are 1's or not in the subsequent years.&amp;nbsp; Notice the colon:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a_0:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That refers to all variable names that begin with "a_0", making them all part of the array.&amp;nbsp; Technically, that's a mistake and should be expanded to also include variable names that begin with "a_1" so the full list of array elements should be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array years {*} a_0: a_1: ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a separate variable ("years") that captures the year designation (0405, 0506, etc.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Nov 2018 13:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-years-in-variable-names-in-macro/m-p/512177#M137915</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-11-12T13:27:19Z</dc:date>
    </item>
  </channel>
</rss>

