<?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: How to select variable (with a year in the name) for calculation based on valued of a date field in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238278#M6163</link>
    <description>&lt;P&gt;I totally agree with LinusH here. &amp;nbsp;You have put "data" into column headings. &amp;nbsp;This will cause you problems with anykind of processing you do on that data. &amp;nbsp;Separate your processing data (with data in columns) and report data (transposed data with data in headers),&lt;/P&gt;</description>
    <pubDate>Tue, 08 Dec 2015 14:28:10 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2015-12-08T14:28:10Z</dc:date>
    <item>
      <title>How to select variable (with a year in the name) for calculation based on valued of a date field</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238264#M6160</link>
      <description>&lt;P&gt;With SAS SQL (or just SAS) I need to use a variable for a calculation based on the year portion of a different date field. The variable's name contains the year that I'd need to match from the year portion of the other date variable. How can I select the right variable to use for my calculation?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, I need to select which one of these to use:&lt;/P&gt;&lt;P&gt;GRADE_2013&lt;/P&gt;&lt;P&gt;GRADE_2014&lt;/P&gt;&lt;P&gt;GRADE_2015&lt;/P&gt;&lt;P&gt;by looking at a date field of the format '15JAN2014'd - so from that year of 2014 I want to grab the value from&amp;nbsp;GRADE_2014&amp;nbsp;to use in another calculation.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2015 14:11:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238264#M6160</guid>
      <dc:creator>reneerabbit</dc:creator>
      <dc:date>2015-12-08T14:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to select variable (with a year in the name) for calculation based on valued of a date field</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238271#M6161</link>
      <description>&lt;P&gt;Not knowing what kind of calculating&amp;nbsp;you wish to make, but usually data and calculations benefit&amp;nbsp;from having data in normalized fashion.&lt;/P&gt;
&lt;P&gt;In your case, it means transposing from wide to long:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id year Grade&lt;/P&gt;
&lt;P&gt;1 2013 A&lt;/P&gt;
&lt;P&gt;1 2014 B&lt;/P&gt;
&lt;P&gt;1 2015 A&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Describing your whole business requirement, and full layout&amp;nbsp;of your dataset helps to get adequate&amp;nbsp;answers.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2015 14:17:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238271#M6161</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-12-08T14:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to select variable (with a year in the name) for calculation based on valued of a date field</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238278#M6163</link>
      <description>&lt;P&gt;I totally agree with LinusH here. &amp;nbsp;You have put "data" into column headings. &amp;nbsp;This will cause you problems with anykind of processing you do on that data. &amp;nbsp;Separate your processing data (with data in columns) and report data (transposed data with data in headers),&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2015 14:28:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238278#M6163</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-12-08T14:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to select variable (with a year in the name) for calculation based on valued of a date field</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238312#M6165</link>
      <description>&lt;P&gt;You received answers to your question here:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://stackoverflow.com/questions/34076789/how-to-select-variable-with-a-year-in-the-name-for-calculation-based-on-value" target="_blank"&gt;http://stackoverflow.com/questions/34076789/how-to-select-variable-with-a-year-in-the-name-for-calculation-based-on-value&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Does the answer not work for you somehow? If not, please post how.&lt;/P&gt;
&lt;P&gt;Answer reposted here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data One;
set Have;
array grades(2013:2015) grade_2013-grade_2015;

*Array method;
variable_want1 = grades(year(date_field));

*VValueX method;
variable_want2 = vvaluex('grades_'||put(year(date_field), 4.));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Dec 2015 16:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238312#M6165</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-08T16:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to select variable (with a year in the name) for calculation based on valued of a date field</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238328#M6166</link>
      <description>&lt;P&gt;Sorry - I was trying to simplify and abstract the issue. &amp;nbsp;Here is more detail and the exact question I'm trying to answer - it differs a bit from my contrived example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've constructed a table that consists of a row for each individual sale that includes:&lt;BR /&gt;-the date sold and&lt;BR /&gt;-the date when service on that product sale ended/terminated.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Also appended from another source are:&lt;BR /&gt;-the characteristics of the person making the sale and&lt;BR /&gt;-the characteristics of the person providing service on the product.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The salesperson/service provider characteristics consist of a two categorical variables that are added annually: basically two different award categories for each of the last 15 years - 30 columns of data at this point.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;My task is to find the relationship, if any, of the award levels at the time of the sale and the time of the service end date. I have those dates ('31jan&lt;STRONG&gt;2013&lt;/STRONG&gt;'d) but I have to then relate those to the correct year of the salesperson's award characteristics. So if the sale was made in &lt;STRONG&gt;2013&lt;/STRONG&gt; then I need to know the value of AWARD1_&lt;STRONG&gt;2013&lt;/STRONG&gt; (picking it from AWARD1_2000 through AWARD1_2015). The same thing for AWARD2_2013. The process is similar for the service termination date and the characteristics at that year date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is currently a table of more than 500k sales (rows) and 100 columns (sales and salespersons/service provider characteristics).&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2015 16:44:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238328#M6166</guid>
      <dc:creator>reneerabbit</dc:creator>
      <dc:date>2015-12-08T16:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to select variable (with a year in the name) for calculation based on valued of a date field</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238337#M6167</link>
      <description>&lt;P&gt;I'm not a programmer by trade and I have no knowledge of how to use arrays...and when I tried to use VVALUES I got an error that "the function VVALUES is unknown" leading me to think that my version/setup of SAS can't use the VVALUES function. &amp;nbsp;So I'm looking for alternatives that hopefully I can implement more quickly.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2015 16:56:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238337#M6167</guid>
      <dc:creator>reneerabbit</dc:creator>
      <dc:date>2015-12-08T16:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to select variable (with a year in the name) for calculation based on valued of a date field</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238340#M6168</link>
      <description>You won't find a faster method than an array. There was a typo, thanks to autocorrect - the function is VVALUEX.</description>
      <pubDate>Tue, 08 Dec 2015 16:58:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238340#M6168</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-08T16:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to select variable (with a year in the name) for calculation based on valued of a date field</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238343#M6169</link>
      <description>Arrays in SAS are shortcut references to variables. You create an array by declaring an array, stating the dimensions and then listing the variables that are references, grade2012-2014.  You can index an array with years, instead of 1-n. So if &lt;BR /&gt;I declare an array&lt;BR /&gt;&lt;BR /&gt;array grades(2014:2016) grades2014-grades20156;&lt;BR /&gt;&lt;BR /&gt;Then I can reference the variables as&lt;BR /&gt;grades(2014) -&amp;gt; grades2014 variable&lt;BR /&gt;grades(2015) - &amp;gt; grades2015 variable&lt;BR /&gt;grades(2015) -&amp;gt; grades 2016 variable.&lt;BR /&gt;&lt;BR /&gt;Here's a paper that does a quick introduction to arrays.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www2.sas.com/proceedings/sugi30/242-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/242-30.pdf&lt;/A&gt;</description>
      <pubDate>Tue, 08 Dec 2015 17:09:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238343#M6169</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-08T17:09:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to select variable (with a year in the name) for calculation based on valued of a date field</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238353#M6170</link>
      <description>&lt;P&gt;Thanks for pointing out VVALUE&lt;STRONG&gt;X -&lt;/STRONG&gt; that seems to be working - transposing with 500k records seems unwieldy and learning arrays "in the heat of the battle" is not optimal at the moment.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2015 18:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238353#M6170</guid>
      <dc:creator>reneerabbit</dc:creator>
      <dc:date>2015-12-08T18:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to select variable (with a year in the name) for calculation based on valued of a date field</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238354#M6171</link>
      <description>One reason not to use VVALUEX is that it returns a character variable instead of numeric. You may need to account for this in the further processing of your data.</description>
      <pubDate>Tue, 08 Dec 2015 18:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-variable-with-a-year-in-the-name-for-calculation/m-p/238354#M6171</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-08T18:25:07Z</dc:date>
    </item>
  </channel>
</rss>

