<?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: Apply two types of floors to the dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Apply-two-types-of-floors-to-the-dataset/m-p/928512#M365308</link>
    <description>&lt;P&gt;One possible interpretation of what you appear to be asking for is to calculate a running maximum values of COL2.&amp;nbsp; With the added feature of starting with the third value&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  if _n_=1 then set have(firstobs=3 obs=3 rename=(col2=running_max));
  set have;
  running_max=max(running_max,col2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or possibly the value where col1=3.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  if _n_=1 then do;
    set have(obs=1 rename=(col2=running_max));
    where col1=3;
  end;
  set have;
  running_max=max(running_max,col2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;               running_
Obs    Col1       max      Col2

 1       1         3         1
 2       2         3         2
 3       3         3         3
 4       4         4         4
 5       5         4         3
 6       6         6         6
 7       7         6         1
 8       8         6         3
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 May 2024 16:59:27 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-05-15T16:59:27Z</dc:date>
    <item>
      <title>Apply two types of floors to the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Apply-two-types-of-floors-to-the-dataset/m-p/928500#M365302</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to apply two types of floors, respectively for lower and upper segments of a dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Assume the dataset has two columns: Col1 which is unique and asc sorted; Col2 is the actual data&amp;nbsp; the floor applies to&lt;/P&gt;&lt;P&gt;1) Floor 1 on the lower band of Col1 : for any values in Col1&lt;SPAN&gt;&amp;nbsp; less than3, which is set to by the user -&amp;nbsp;&lt;/SPAN&gt;replace their values in Col2 with the Col2 value of Col1 =3&lt;/P&gt;&lt;P&gt;2)Floor 2 on the upper band of Col1:&amp;nbsp;for any values in Col1&lt;SPAN&gt;&amp;nbsp; greater than 4, which is set to by the user -&amp;nbsp;&lt;/SPAN&gt;replace their values in Col2 with the Col2 value of previous Col1 to ensure they are not decreasing when Col1 values increase&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is an example of the dataset I have and what I want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input Col1 Col2;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1&lt;BR /&gt;2 2&lt;BR /&gt;3 3&lt;BR /&gt;4 4&lt;BR /&gt;5 3&lt;BR /&gt;6 6&lt;BR /&gt;7 1&lt;BR /&gt;8 3&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;Col1 Col2&lt;BR /&gt;1 3&lt;BR /&gt;2 3&lt;BR /&gt;3 3&lt;BR /&gt;4 4&lt;BR /&gt;5 4&lt;BR /&gt;6 6&lt;BR /&gt;7 6&lt;BR /&gt;8 6&lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2024 16:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Apply-two-types-of-floors-to-the-dataset/m-p/928500#M365302</guid>
      <dc:creator>fwu811</dc:creator>
      <dc:date>2024-05-15T16:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Apply two types of floors to the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Apply-two-types-of-floors-to-the-dataset/m-p/928503#M365304</link>
      <description>&lt;P&gt;I do NOT understand your data structure.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why would using the "Col2 value of Col1 =3" make any sense at all?&amp;nbsp; What is the meaning of COL1?&amp;nbsp; What is the meaning of COL2.&amp;nbsp; What is the relationship between COL1 and COL2?&amp;nbsp; What is the meaning of 3?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that value is so important why not just put it into its own variable, or perhaps its own dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why are you calling this operation a FLOOR?&amp;nbsp; That word usually means a lower bound on the possible value.&amp;nbsp; So if the floor is set at 23 and the current value is only 20 you would need to raise it to 23 do that it does not drop below the floor.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you trying to set a BAND or RANGE that the values cannot be outside of?&amp;nbsp; So if the minimum value should be 20 and maximum value should be 40 then the adjustment might be something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;want = max(20,min(have,40));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So that values over 40, like 45, would map to 40 and values under 20, like 15, would map to 20 but values between 20 to 40, like 25,&amp;nbsp; would be unchanged.&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2024 16:40:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Apply-two-types-of-floors-to-the-dataset/m-p/928503#M365304</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-05-15T16:40:08Z</dc:date>
    </item>
    <item>
      <title>Re: Apply two types of floors to the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Apply-two-types-of-floors-to-the-dataset/m-p/928512#M365308</link>
      <description>&lt;P&gt;One possible interpretation of what you appear to be asking for is to calculate a running maximum values of COL2.&amp;nbsp; With the added feature of starting with the third value&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  if _n_=1 then set have(firstobs=3 obs=3 rename=(col2=running_max));
  set have;
  running_max=max(running_max,col2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or possibly the value where col1=3.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  if _n_=1 then do;
    set have(obs=1 rename=(col2=running_max));
    where col1=3;
  end;
  set have;
  running_max=max(running_max,col2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;               running_
Obs    Col1       max      Col2

 1       1         3         1
 2       2         3         2
 3       3         3         3
 4       4         4         4
 5       5         4         3
 6       6         6         6
 7       7         6         1
 8       8         6         3
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2024 16:59:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Apply-two-types-of-floors-to-the-dataset/m-p/928512#M365308</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-05-15T16:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: Apply two types of floors to the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Apply-two-types-of-floors-to-the-dataset/m-p/928646#M365382</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply, which is useful for all Col1 values less than 3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The purpose of these checks are due to poor quality of data at both ends.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I only want to apply the max Col2 value check for a certain range of Col1 values, e.g., when it is greater than 6, so the data I want are:&lt;/P&gt;&lt;P&gt;data want:&lt;/P&gt;&lt;P&gt;1 3&lt;BR /&gt;2 3&lt;BR /&gt;3 3&lt;BR /&gt;4 4&lt;BR /&gt;5 3&lt;BR /&gt;6 6&lt;BR /&gt;7 6&lt;BR /&gt;8 6&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you amend your code for this purpose?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2024 12:50:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Apply-two-types-of-floors-to-the-dataset/m-p/928646#M365382</guid>
      <dc:creator>fwu811</dc:creator>
      <dc:date>2024-05-16T12:50:33Z</dc:date>
    </item>
  </channel>
</rss>

