<?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 do I update all observations of a variable (9.4) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-all-observations-of-a-variable-9-4/m-p/413531#M101221</link>
    <description>&lt;P&gt;I am a novice SAS user and I am working with this data set and there is a variable called "Status" that keeps track of the current status of the companies right now, either "A" (active) or "I" (inactive). The data is collected from different periods so sometimes the status was "active" for a period but later on it went "inactive". The last Status is always the correct one, so I'd like to know how to change all the Status observations of a company to its last value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been squeezing my brain and looking up all over the web and SAS communities. I've tried retain last. first. functions, conditional, loops,... so far, but I can't find the answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Enclosed is the preview of my results so far. As you can see in the last day of 2013 the company was still active, but at some point from then until now it went inactive and the final status changed right there (red circle). Again, where does the status change in the dataset is not important, if it is "Inactive" anywhere all status should be "inactive", otherwise all status should be "active".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas or directions will be much appreciated. Thank you very much in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sascom.jpg" style="width: 500px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16645i6421BC253B47F879/image-size/large?v=v2&amp;amp;px=999" role="button" title="sascom.jpg" alt="sascom.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Nov 2017 23:53:24 GMT</pubDate>
    <dc:creator>KrisDeng</dc:creator>
    <dc:date>2017-11-14T23:53:24Z</dc:date>
    <item>
      <title>How do I update all observations of a variable (9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-all-observations-of-a-variable-9-4/m-p/413531#M101221</link>
      <description>&lt;P&gt;I am a novice SAS user and I am working with this data set and there is a variable called "Status" that keeps track of the current status of the companies right now, either "A" (active) or "I" (inactive). The data is collected from different periods so sometimes the status was "active" for a period but later on it went "inactive". The last Status is always the correct one, so I'd like to know how to change all the Status observations of a company to its last value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been squeezing my brain and looking up all over the web and SAS communities. I've tried retain last. first. functions, conditional, loops,... so far, but I can't find the answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Enclosed is the preview of my results so far. As you can see in the last day of 2013 the company was still active, but at some point from then until now it went inactive and the final status changed right there (red circle). Again, where does the status change in the dataset is not important, if it is "Inactive" anywhere all status should be "inactive", otherwise all status should be "active".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas or directions will be much appreciated. Thank you very much in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sascom.jpg" style="width: 500px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16645i6421BC253B47F879/image-size/large?v=v2&amp;amp;px=999" role="button" title="sascom.jpg" alt="sascom.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 23:53:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-all-observations-of-a-variable-9-4/m-p/413531#M101221</guid>
      <dc:creator>KrisDeng</dc:creator>
      <dc:date>2017-11-14T23:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do I update all observations of a variable (9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-all-observations-of-a-variable-9-4/m-p/413533#M101222</link>
      <description>&lt;P&gt;That's not clear. Do you want the latest status or that if it's inactive anytime it's inactive always?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post sample data in text format so we can work with it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are many possible&amp;nbsp;solutions, one is a sort and then using FIRST and RETAIN.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/177650"&gt;@KrisDeng&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I am a novice SAS user and I am working with this data set and there is a variable called "Status" that keeps track of the current status of the companies right now, either "A" (active) or "I" (inactive). The data is collected from different periods so sometimes the status was "active" for a period but later on it went "inactive". The last Status is always the correct one, so I'd like to know how to change all the Status observations of a company to its last value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have been squeezing my brain and looking up all over the web and SAS communities. I've tried retain last. first. functions, conditional, loops,... so far, but I can't find the answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Enclosed is the preview of my results so far. As you can see in the last day of 2013 the company was still active, but at some point from then until now it went inactive and the final status changed right there (red circle). Again, where does the status change in the dataset is not important, if it is "Inactive" anywhere all status should be "inactive", otherwise all status should be "active".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas or directions will be much appreciated. Thank you very much in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sascom.jpg" style="width: 500px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16645i6421BC253B47F879/image-size/large?v=v2&amp;amp;px=999" role="button" title="sascom.jpg" alt="sascom.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 00:15:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-all-observations-of-a-variable-9-4/m-p/413533#M101222</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-15T00:15:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I update all observations of a variable (9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-all-observations-of-a-variable-9-4/m-p/413536#M101223</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your quick reply. I would like to have all the status the same, and similar to the last one. This way readers will see if the company is currently active right now, even if they are looking at an older observation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached is the sample of the data for a company fully from it's first to last observation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 00:21:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-all-observations-of-a-variable-9-4/m-p/413536#M101223</guid>
      <dc:creator>KrisDeng</dc:creator>
      <dc:date>2017-11-15T00:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I update all observations of a variable (9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-all-observations-of-a-variable-9-4/m-p/413537#M101224</link>
      <description>&lt;P&gt;1. Sort by company and descending date -&amp;gt; PROC SORT&lt;/P&gt;
&lt;P&gt;2. In a Data Step use BY groups. At the first record (first.VARIABLENAME) of a company it will be the latest status. Create a new variable called LAST_STATUS and set it to the value. &amp;nbsp;Make sure the variable has a RETAIN&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;retain latest_status;

set have;
by company descending date;

if first.company then latest_status = Status;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have trouble with the exact implementation post your full code, log and detail why it isn't working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/177650"&gt;@KrisDeng&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your quick reply. I would like to have all the status the same, and similar to the last one. This way readers will see if the company is currently active right now, even if they are looking at an older observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Attached is the sample of the data for a company fully from it's first to last observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 00:36:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-all-observations-of-a-variable-9-4/m-p/413537#M101224</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-15T00:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I update all observations of a variable (9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-all-observations-of-a-variable-9-4/m-p/413538#M101225</link>
      <description>&lt;P&gt;Assuming your data set is in sorted order BY COMPANY DATE, you can do this in one step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;do until (last.company);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;by company;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;last_status = status;&lt;/P&gt;
&lt;P&gt;do until (last.company);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;by company;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The top loop reads all the observations for a company, providing the final value for STATUS.&amp;nbsp; Then the bottom loop reads the same observations and outputs them.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 00:52:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-all-observations-of-a-variable-9-4/m-p/413538#M101225</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-11-15T00:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I update all observations of a variable (9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-all-observations-of-a-variable-9-4/m-p/413543#M101229</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It worked out beautifully. Thank you very much. I am sure your support will be of great help for me to further studying SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 01:32:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-all-observations-of-a-variable-9-4/m-p/413543#M101229</guid>
      <dc:creator>KrisDeng</dc:creator>
      <dc:date>2017-11-15T01:32:13Z</dc:date>
    </item>
  </channel>
</rss>

