<?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: Creating a cohort variable by a date of event in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-cohort-variable-by-a-date-of-event/m-p/956918#M373599</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/472304"&gt;@PHOEpiDoc&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your response! I still get the same- only the occasional 3 and the rest 2's. I wonder if the data is being imported in a way that isn't representative of the date in excel. Is there a way to check that?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Show you data.&amp;nbsp; Do you have date or time or datetime?&amp;nbsp; Internal(unformatted)and external(formatted)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Jan 2025 21:55:00 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2025-01-22T21:55:00Z</dc:date>
    <item>
      <title>Creating a cohort variable by a date of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-cohort-variable-by-a-date-of-event/m-p/956915#M373596</link>
      <description>&lt;P&gt;I have a bunch of data from the Electronic Medical Record, and I am trying to create two cohorts of patients: those that had a time of death before July1, 2023 at midnight, and after. I have tried and tried, and keep failing. The variable "Time_of_Death" is a numeric DateTime16 variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Code is:&lt;/P&gt;&lt;PRE&gt;DATA	PallImpt.Cohorts;
	SET	PallImpt.Source;

	IF			Time_of_Death &amp;lt; '01JUL2023'd then Cohort = 1;
	IF			Time_of_Death &amp;gt; '01JUL2023'd then Cohort = 2;
	else cohort = 3;
	run&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;However, when I look at the results, I get only cohorts 2 and 3 (if missing), but the dates that should be a "1" are a "2".&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I doing wrong?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 21:34:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-cohort-variable-by-a-date-of-event/m-p/956915#M373596</guid>
      <dc:creator>PHOEpiDoc</dc:creator>
      <dc:date>2025-01-22T21:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a cohort variable by a date of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-cohort-variable-by-a-date-of-event/m-p/956916#M373597</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	PallImpt.Cohorts;
	SET	PallImpt.Source;

	IF			Time_of_Death &amp;lt; '01JUL2023'd then Cohort = 1;
	&lt;FONT color="#FF6600"&gt;ELSE&lt;/FONT&gt; IF		Time_of_Death &amp;gt; '01JUL2023'd then Cohort = 2;
	else cohort = 3;
	run &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The missing ELSE is overwriting any COHORT=1.&amp;nbsp; if you have missing values for Time_of_death they will be COHORT=1 not COHORT=3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just notice this&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;The variable "Time_of_Death" is a numeric DateTime16 variable.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;You need date time constant '&lt;CODE class=" language-sas"&gt;01JUL2023:00:00'dt&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	PallImpt.Cohorts;
	SET	PallImpt.Source;
    if missing(Time_of_death)                then cohort = 3;
	ELSE IF		Time_of_Death &amp;lt; '01JUL2023:00:00'dt then Cohort = 1;
	ELSE IF		Time_of_Death &amp;gt; '01JUL2023:00:00'dt then Cohort = 2;
	run &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That should work I think&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 22:06:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-cohort-variable-by-a-date-of-event/m-p/956916#M373597</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2025-01-22T22:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a cohort variable by a date of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-cohort-variable-by-a-date-of-event/m-p/956917#M373598</link>
      <description>&lt;P&gt;Thanks for your response! I still get the same- only the occasional 3 and the rest 2's. I wonder if the data is being imported in a way that isn't representative of the date in excel. Is there a way to check that?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 21:51:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-cohort-variable-by-a-date-of-event/m-p/956917#M373598</guid>
      <dc:creator>PHOEpiDoc</dc:creator>
      <dc:date>2025-01-22T21:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a cohort variable by a date of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-cohort-variable-by-a-date-of-event/m-p/956918#M373599</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/472304"&gt;@PHOEpiDoc&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your response! I still get the same- only the occasional 3 and the rest 2's. I wonder if the data is being imported in a way that isn't representative of the date in excel. Is there a way to check that?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Show you data.&amp;nbsp; Do you have date or time or datetime?&amp;nbsp; Internal(unformatted)and external(formatted)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 21:55:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-cohort-variable-by-a-date-of-event/m-p/956918#M373599</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2025-01-22T21:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a cohort variable by a date of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-cohort-variable-by-a-date-of-event/m-p/956924#M373600</link>
      <description>&lt;P&gt;DATE values are stored in DAYS and DATETIME values are stored in SECONDS. There are 24*60*60 seconds in a day.&amp;nbsp; So pretty much and DATETIME value after early morning on 01JAN1960 is going to be larger than '01JUL2003'd since that is day number&amp;nbsp;15,887.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1    data _null_;
2      date='01JUL2003'd ;
3      put date= comma. date=date9. date=datetime19.;
4    run;

date=15,887 date=01JUL2003 date=01JAN1960:04:24:47
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So either convert your DATETIME values into DATE values using the DATEPART() function.&amp;nbsp;Or compare the values to DATETIME constants instead of DATE constants.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also make sure to figure out what cohort the time stamp of midnight on 01JUL2003 should be included in.&amp;nbsp; Right now you have it in COHORT 3.&amp;nbsp; Also remember that missing values are smaller than any actual value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code will place 01JUL2003 in COHORT 1 and place only missing values in COHORT 3.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data PallImpt.Cohorts;
  set PallImpt.Source;
  if datepart(Time_of_Death) &amp;gt; '01JUL2023'd then Cohort = 2;
  else if missing(Time_of_Death) then cohort = 3;
  else cohort=1;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 22:17:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-cohort-variable-by-a-date-of-event/m-p/956924#M373600</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-22T22:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a cohort variable by a date of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-cohort-variable-by-a-date-of-event/m-p/956927#M373601</link>
      <description>&lt;P&gt;I think I figured it out! It was a formatting problem in Excel. Thank you so much for your help- I wouldn't have looked at excel without you helping with the SAS side.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 22:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-cohort-variable-by-a-date-of-event/m-p/956927#M373601</guid>
      <dc:creator>PHOEpiDoc</dc:creator>
      <dc:date>2025-01-22T22:21:44Z</dc:date>
    </item>
  </channel>
</rss>

