<?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 keep the previous value to the current one? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-the-previous-value-to-the-current-one/m-p/907978#M358377</link>
    <description>&lt;P&gt;I don't see the folder variable in your picture.&lt;/P&gt;
&lt;P&gt;Do not post data in pictures. Post data as text, ideally in a DATA step with DATALINES. Use the "little running man" button to post code, it will keep the original formatting (which is eaten by the main posting window).&lt;/P&gt;
&lt;P&gt;As long as we do not have usable data to work with (we can't copy/paste a picture into the program editor), it is hard to help you.&lt;/P&gt;</description>
    <pubDate>Thu, 14 Dec 2023 08:24:34 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-12-14T08:24:34Z</dc:date>
    <item>
      <title>How to keep the previous value to the current one?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-the-previous-value-to-the-current-one/m-p/907973#M358373</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi guys! I am doing one sdtm project question,&lt;/P&gt;&lt;P&gt;there is one variable "folder" to keep the visiting week values like "week1" "screening" "week5";&amp;nbsp; also, we want to create a new variable "visitnum" to extract the numbers of folder, like if folder=week5, so we keep 5 for the visitnum;&lt;/P&gt;&lt;P&gt;when the folder="SRV", we want to keep the previous value of visitnum; like for observation80, we have folder="SRV", so we keep the previous obs(79) visitnum=43, and we get the visitnum=43+0.01;&lt;/P&gt;&lt;P&gt;I am trying to use RETAIN and lag function to keep the previous value, I don't know why the prev_visit value is correct, but the visitnum is keep the previous 2 value +0.01? like for the observation when prev_visit=43, &amp;nbsp;I hope to get visitnum=43.01 not 36.01.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2023-12-14 at 2.50.17 AM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/91365i6E8D18C2EA63643F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2023-12-14 at 2.50.17 AM.png" alt="Screenshot 2023-12-14 at 2.50.17 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Can you help me to fix it? Thank!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data vs_vs3;&lt;BR /&gt;set vs_vs2;&lt;BR /&gt;retain prev_visit;&lt;BR /&gt;length visit $14;&lt;BR /&gt;if first.vetest then prev_visit=.;&lt;/P&gt;&lt;P&gt;if folder="SCREENING" then do;&lt;BR /&gt;visitnum= -1;&lt;BR /&gt;visit="Screening";&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;else if index(upcase(folder),"WEEK") then do;&lt;BR /&gt;visitnum= substr(folder,5)*7-6;&lt;BR /&gt;visit="Screening";&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;else if index(upcase(folder),"SRV") then do;&lt;BR /&gt;visitnum = prev_visit +0.01;&lt;BR /&gt;visit="Systemic"||"-"||strip(put(visitnum,best12.));&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;else if index(upcase(folder),"UNS")then do;&lt;BR /&gt;visitnum = prev_visit +0.01;&lt;BR /&gt;visit="Unsched"||"-"||strip(put(visitnum,best12.));&lt;BR /&gt;end;&lt;BR /&gt;prev_visit = lag(visitnum);&lt;BR /&gt;*drop prev_visit;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2023 07:52:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-the-previous-value-to-the-current-one/m-p/907973#M358373</guid>
      <dc:creator>Sikcion</dc:creator>
      <dc:date>2023-12-14T07:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep the previous value to the current one?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-the-previous-value-to-the-current-one/m-p/907978#M358377</link>
      <description>&lt;P&gt;I don't see the folder variable in your picture.&lt;/P&gt;
&lt;P&gt;Do not post data in pictures. Post data as text, ideally in a DATA step with DATALINES. Use the "little running man" button to post code, it will keep the original formatting (which is eaten by the main posting window).&lt;/P&gt;
&lt;P&gt;As long as we do not have usable data to work with (we can't copy/paste a picture into the program editor), it is hard to help you.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2023 08:24:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-the-previous-value-to-the-current-one/m-p/907978#M358377</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-12-14T08:24:34Z</dc:date>
    </item>
  </channel>
</rss>

