<?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 sum horizontally from af certain point (specific value appears) in the row and 52 weeks ahead in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sum-horizontally-from-af-certain-point-specific-value/m-p/217996#M53622</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;Good idea to provide some test data/ required output.&amp;nbsp; You should be able to do this using the SUM() function in SQL, by using where clauses and sub-queries with min().&amp;nbsp; Something like:&lt;/P&gt;&lt;P&gt;select&amp;nbsp; COUNT(1)&lt;/P&gt;&lt;P&gt;from&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BASE_DATASET A&lt;/P&gt;&lt;P&gt;where&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATE &amp;gt; (select DATE from BASE_DATESET where FLAG=1 and MIN(DATE))&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 09 Apr 2015 13:57:02 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2015-04-09T13:57:02Z</dc:date>
    <item>
      <title>How to sum horizontally from af certain point (specific value appears) in the row and 52 weeks ahead</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sum-horizontally-from-af-certain-point-specific-value/m-p/217994#M53620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We have a question about how to sum horizontally in SAS. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Our dataset contains several horizontal rows, each one representing a person. &lt;/P&gt;&lt;P&gt;Each column represents one week and all the week-variables are numeric (the time period is from year 1999-2001, thus the total number of columns/weeks is 52&lt;EM&gt;52&lt;/EM&gt;52=156)&lt;/P&gt;&lt;P&gt;All observations contain one of the following values: “1”, “0” or “.” (“.” = missing values). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We would really appreciate if anyone would like to help us with a SAS code enabling us to sum one row horizontally (i.e. a time period for each person of the dataset) and thereby generate a variable, which shows the sum from the first time you meet the value “1” in a row and from that point sums 52 weeks ahead (1 year).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The “1” observations do not necessarily have to be coherent in the row, i.e. even though the sum-variable meets the value “0” or “.” it shall continue summing from the starting point (first time meeting the “1”) and 52 weeks ahead. &lt;/P&gt;&lt;P&gt;The first observed “1” has to be placed in a week in the period 1999-2001, but the following observations are also allowed to be places outside the period (e.g. in year 2002), as long as the first observation is placed in a week between 1999-2001.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance. &lt;/P&gt;&lt;P&gt;Best regards, &lt;/P&gt;&lt;P&gt;Maria and Sissel &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Apr 2015 08:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-sum-horizontally-from-af-certain-point-specific-value/m-p/217994#M53620</guid>
      <dc:creator>Maria_Sissel</dc:creator>
      <dc:date>2015-04-09T08:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum horizontally from af certain point (specific value appears) in the row and 52 weeks ahead</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sum-horizontally-from-af-certain-point-specific-value/m-p/217995#M53621</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Maria, hi Sissel,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from what I have understood, your data looks like this:&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Person&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;1/1999&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;2/1999&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;3/1999&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;abc&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;.&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;.&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;def&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;.&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;acb&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;.&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;bca&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;cba&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;.&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;.&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;While there may surely be several approaches to solve this, I would try to transpose the data and make it look like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;Person&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;Week&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;value&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;abc&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1/1999&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;abc&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2/1999&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;abc&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3/1999&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;def&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1/1999&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;def&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2/1999&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;def&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3/1999&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;acb&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1/1999&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From then on you could just use a DataStep with retain statement to calculate the values and then output the specific results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does this help?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers, Michael&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Apr 2015 13:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-sum-horizontally-from-af-certain-point-specific-value/m-p/217995#M53621</guid>
      <dc:creator>mfab</dc:creator>
      <dc:date>2015-04-09T13:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum horizontally from af certain point (specific value appears) in the row and 52 weeks ahead</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sum-horizontally-from-af-certain-point-specific-value/m-p/217996#M53622</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;Good idea to provide some test data/ required output.&amp;nbsp; You should be able to do this using the SUM() function in SQL, by using where clauses and sub-queries with min().&amp;nbsp; Something like:&lt;/P&gt;&lt;P&gt;select&amp;nbsp; COUNT(1)&lt;/P&gt;&lt;P&gt;from&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BASE_DATASET A&lt;/P&gt;&lt;P&gt;where&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATE &amp;gt; (select DATE from BASE_DATESET where FLAG=1 and MIN(DATE))&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Apr 2015 13:57:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-sum-horizontally-from-af-certain-point-specific-value/m-p/217996#M53622</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-04-09T13:57:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum horizontally from af certain point (specific value appears) in the row and 52 weeks ahead</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sum-horizontally-from-af-certain-point-specific-value/m-p/217997#M53623</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, I've got to assume that this data exists in SAS, and you know the names of the variables.&amp;nbsp; You could code it this way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; array weeks {*} list of all week variables in order starting with Jan1999;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; total = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do _i_=1 to 156 until (first_1 &amp;gt; .);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if weeks{_i_}=1 then first_1 = _i_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if (. &amp;lt; first_1 &amp;lt;= 156) then do _i_ = first_1 to min(first_1 + 52, dim(weeks));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; total + weeks{_i_};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first loop locates the first "1".&amp;nbsp; The second loop sums from that point.&amp;nbsp; It's up to you whether you use first_1 + 52 (a total of 53 weeks) or first_1 + 51 (a total of 52 weeks).&amp;nbsp; The code is obviously untested, but should be easy enough to work with.&amp;nbsp; Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Apr 2015 15:02:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-sum-horizontally-from-af-certain-point-specific-value/m-p/217997#M53623</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-04-09T15:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum horizontally from af certain point (specific value appears) in the row and 52 weeks ahead</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sum-horizontally-from-af-certain-point-specific-value/m-p/217998#M53624</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much!! Your answer is correct and really helpful &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 18 Apr 2015 10:43:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-sum-horizontally-from-af-certain-point-specific-value/m-p/217998#M53624</guid>
      <dc:creator>Maria_Sissel</dc:creator>
      <dc:date>2015-04-18T10:43:52Z</dc:date>
    </item>
  </channel>
</rss>

