<?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 cap the value of existing column based on date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-cap-the-value-of-existing-column-based-on-date/m-p/827444#M326851</link>
    <description>&lt;P&gt;Can you show the log of those steps run back to back?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FYI -&amp;nbsp; this type of coding is usually dangerous and can make things hard to debug/trace.&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;data libname.abc;
	set libname.abc;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Aug 2022 21:10:49 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-08-05T21:10:49Z</dc:date>
    <item>
      <title>How to cap the value of existing column based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-cap-the-value-of-existing-column-based-on-date/m-p/827443#M326850</link>
      <description>&lt;P&gt;This is the code that I wrote:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data libname.abc;
	set libname.abc;
	if num_var &amp;gt; 72 and date_var &amp;lt; '08FEB2022'd then num_var = 72;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This was supposed to cap the value of num_var at 72 if it was before that specific date. However, when I open the table libname.abc on SAS EG and put numvar&amp;gt;72 after clicking on the where button, I see several records where the date_var has a value from years before 2022. Please note that date_var is a datetime variable.&lt;/P&gt;
&lt;P&gt;However, when I query it as follows it doesn't return any rows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table temp_abc as
	select * from libname.abc where num_var &amp;gt; 72 and date_var &amp;lt; '08FEB2022'd;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This eventually makes me think there's something wrong with the data step condition but I can't figure out what it is.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2022 21:04:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-cap-the-value-of-existing-column-based-on-date/m-p/827443#M326850</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2022-08-05T21:04:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to cap the value of existing column based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-cap-the-value-of-existing-column-based-on-date/m-p/827444#M326851</link>
      <description>&lt;P&gt;Can you show the log of those steps run back to back?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FYI -&amp;nbsp; this type of coding is usually dangerous and can make things hard to debug/trace.&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;data libname.abc;
	set libname.abc;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2022 21:10:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-cap-the-value-of-existing-column-based-on-date/m-p/827444#M326851</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-08-05T21:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to cap the value of existing column based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-cap-the-value-of-existing-column-based-on-date/m-p/827445#M326852</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/355241"&gt;@aalluru&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This is the code that I wrote:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data libname.abc;
	set libname.abc;
	if num_var &amp;gt; 72 and date_var &amp;lt; '08FEB2022'd then num_var = 72;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This was supposed to cap the value of num_var at 72 if it was before that specific date. However, when I open the table libname.abc on SAS EG and put numvar&amp;gt;72 after clicking on the where button, I see several records where the date_var has a value from years before 2022.&lt;FONT size="5" color="#FF0000"&gt;&lt;STRONG&gt; Please note that date_var is a datetime variable.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;However, when I query it as follows it doesn't return any rows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table temp_abc as
	select * from libname.abc where num_var &amp;gt; 72 and date_var &amp;lt; '08FEB2022'd;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This eventually makes me think there's something wrong with the data step condition but I can't figure out what it is.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If Date_var is actually a SAS datetime value then the underlying value used for comparisons is measured in SECONDS since 01JAN1960 :00:00:00. You are comparing it to a DATE, which is number of DAYS since 01JAN1960. So your Datetime values, unless they are pretty close to Jan 1960 are a couple of orders of magnitude greater than the date.&lt;/P&gt;
&lt;P&gt;To compare a datetime with a date value use the DATEPART function to get something comparable:&lt;/P&gt;
&lt;PRE&gt;data libname.abc;
	set libname.abc;
	if num_var &amp;gt; 72 and DATEPART(date_var) &amp;lt; '08FEB2022'd then num_var = 72;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates and such.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data and set with the same name means the source data set is completely replaced unless you have a syntax error. Depending on what you are doing that could mean loss of records or recoding values for the same record multiple times.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2022 21:34:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-cap-the-value-of-existing-column-based-on-date/m-p/827445#M326852</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-08-05T21:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to cap the value of existing column based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-cap-the-value-of-existing-column-based-on-date/m-p/827447#M326854</link>
      <description>&lt;P&gt;Unless you have datetime values from before 02JAN1960 they should all be larger than&amp;nbsp;'08FEB2022'd.&lt;/P&gt;
&lt;P&gt;Here is simple code to show what datetime value you actually compare the variable to.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1997  data _null_;
1998    date = '08FEB2022'd ;
1999    put date comma19. / date datetime19. ;
2000    datetime = '08FEB2022:00:00'dt;
2001    put datetime comma19. / datetime datetime19. ;
2002  run;

             22,684
 01JAN1960:06:18:04
      1,959,897,600
 08FEB2022:00:00:00
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So 08EB2022 is over 22 thousand days after the start of 1960.&amp;nbsp; But that number of seconds is only a little over 6 hours after the start of 1960.&lt;/P&gt;
&lt;P&gt;To get a number in the right ball park use a datetime literal instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2022 23:46:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-cap-the-value-of-existing-column-based-on-date/m-p/827447#M326854</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-05T23:46:59Z</dc:date>
    </item>
  </channel>
</rss>

