<?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: Urgent help! Creating a categorical variable out of a date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Urgent-help-Creating-a-categorical-variable-out-of-a-date/m-p/699105#M25578</link>
    <description>&lt;P&gt;You can streamline your code to make it easier to use in the future:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let now='01jul2013'd; /* just one date in 2013 */
/* this is all you have to set in the future */

/* the following calculates the cutoff dates from the initial value */
%let cut1 = %sysfunc(intnx(year,&amp;amp;now.,-1,e));
%let cut7 = %sysfunc(intnx(year,&amp;amp;now.,-8,e));

/* the following is for informational purposes only, you can remove it later */
data _null_;
cut1 = &amp;amp;cut1;
cut7 = &amp;amp;cut7;
put cut1= yymmdd10.;
put cut7= yymmdd10.;
run;

/* this is your streamlined code */
data EA1_2;
set EA1_1;
length TimeSinceDiagnosis $7.;
if diagnosis_dt &amp;gt; &amp;amp;cut1. then TimeSinceDiagnosis = '&amp;lt;1yr';
else if diagnosis_dt  &amp;gt; &amp;amp;cut7. then TimeSinceDiagnosis = '2-7yrs';
else TimeSinceDiagnosis = '&amp;gt;=8yrs';
run;
/* note that the else-if makes some conditions redundant */&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 16 Nov 2020 11:31:03 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-11-16T11:31:03Z</dc:date>
    <item>
      <title>Urgent help! Creating a categorical variable out of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Urgent-help-Creating-a-categorical-variable-out-of-a-date/m-p/699092#M25571</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset in which there is a variable (diagnosis_dt) for which there are values in the DDMONYYYY format. I want to create a categorical variable out of this data, and I want to make 3 categories: &amp;lt;= 1 year, 2-7 years, and &amp;gt;= 8 years.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My original set is EA1_1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I have tried. I admittedly have no idea what I am doing. When I input this, all of my outputs end up being 2-7 years.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data EA1_2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set EA1_1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length TimeSinceDiagnosis $3.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF diagnosis_dt &amp;gt; = '31DEC2012'd &amp;nbsp;THEN TimeSinceDiagnosis ='&amp;lt;1yr';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE IF diagnosis_dt &amp;lt; =&amp;nbsp; '31DEC2012'd or diagnosis_dt &amp;gt; &amp;nbsp;= '31DEC2005'd THEN TimeSinceDiagnosis = '2-7yrs';&lt;/P&gt;&lt;P&gt;ELSE IF diagnosis_dt &amp;lt; =&amp;nbsp; '01JAN2005'd THEN TimeSinceDiagnosis = '&amp;gt; 8yrs';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 10:44:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Urgent-help-Creating-a-categorical-variable-out-of-a-date/m-p/699092#M25571</guid>
      <dc:creator>araren</dc:creator>
      <dc:date>2020-11-16T10:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent help! Creating a categorical variable out of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Urgent-help-Creating-a-categorical-variable-out-of-a-date/m-p/699093#M25572</link>
      <description>&lt;P&gt;Can you show us what your data looks like?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 10:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Urgent-help-Creating-a-categorical-variable-out-of-a-date/m-p/699093#M25572</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-16T10:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent help! Creating a categorical variable out of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Urgent-help-Creating-a-categorical-variable-out-of-a-date/m-p/699096#M25573</link>
      <description>&lt;P&gt;Here is a screenshot of what I am looking at!&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2020-11-16 at 2.48.24 AM.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51698i7105098A9A9D1903/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2020-11-16 at 2.48.24 AM.png" alt="Screen Shot 2020-11-16 at 2.48.24 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 10:50:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Urgent-help-Creating-a-categorical-variable-out-of-a-date/m-p/699096#M25573</guid>
      <dc:creator>araren</dc:creator>
      <dc:date>2020-11-16T10:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent help! Creating a categorical variable out of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Urgent-help-Creating-a-categorical-variable-out-of-a-date/m-p/699099#M25574</link>
      <description>&lt;P&gt;1) Specify a greater length to TimeSinceDiagnosis.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) All the diagnosis dates I can see are before 31DEC2012. So the first else-if statement is always fulfilled, since you specify an OR condition and not an AND condition. That way, you never get to the &amp;gt;8Years part. Try the code below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data EA1_2;
    set EA1_1;
    length TimeSinceDiagnosis $20;

    IF diagnosis_dt &amp;gt; = '31DEC2012'd THEN
        TimeSinceDiagnosis ='&amp;lt;1yr';
    ELSE IF diagnosis_dt &amp;lt; =  '31DEC2012'd&lt;FONT size="5"&gt;&lt;STRONG&gt; and&lt;/STRONG&gt; &lt;/FONT&gt;diagnosis_dt &amp;gt;  = '31DEC2005'd THEN
        TimeSinceDiagnosis = '2-7yrs';
    ELSE IF diagnosis_dt &amp;lt; =  '01JAN2005'd THEN
        TimeSinceDiagnosis = '&amp;gt; 8yrs';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 10:55:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Urgent-help-Creating-a-categorical-variable-out-of-a-date/m-p/699099#M25574</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-16T10:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent help! Creating a categorical variable out of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Urgent-help-Creating-a-categorical-variable-out-of-a-date/m-p/699100#M25575</link>
      <description>&lt;P&gt;Your mistake is here&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ELSE IF diagnosis_dt &amp;lt; =  '31DEC2012'd or diagnosis_dt &amp;gt;  = '31DEC2005'd&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it should be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ELSE IF diagnosis_dt &amp;lt; =  '31DEC2012'd and diagnosis_dt &amp;gt;  = '31DEC2005'd&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Nov 2020 10:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Urgent-help-Creating-a-categorical-variable-out-of-a-date/m-p/699100#M25575</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-16T10:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent help! Creating a categorical variable out of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Urgent-help-Creating-a-categorical-variable-out-of-a-date/m-p/699101#M25576</link>
      <description>It worked! You're right, I didn't understand what the first part of my code meant (the $ and TimeSinceDiagnosis). This helped so much, thank you!</description>
      <pubDate>Mon, 16 Nov 2020 10:58:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Urgent-help-Creating-a-categorical-variable-out-of-a-date/m-p/699101#M25576</guid>
      <dc:creator>araren</dc:creator>
      <dc:date>2020-11-16T10:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent help! Creating a categorical variable out of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Urgent-help-Creating-a-categorical-variable-out-of-a-date/m-p/699102#M25577</link>
      <description>&lt;P&gt;Anytime &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 10:59:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Urgent-help-Creating-a-categorical-variable-out-of-a-date/m-p/699102#M25577</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-16T10:59:03Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent help! Creating a categorical variable out of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Urgent-help-Creating-a-categorical-variable-out-of-a-date/m-p/699105#M25578</link>
      <description>&lt;P&gt;You can streamline your code to make it easier to use in the future:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let now='01jul2013'd; /* just one date in 2013 */
/* this is all you have to set in the future */

/* the following calculates the cutoff dates from the initial value */
%let cut1 = %sysfunc(intnx(year,&amp;amp;now.,-1,e));
%let cut7 = %sysfunc(intnx(year,&amp;amp;now.,-8,e));

/* the following is for informational purposes only, you can remove it later */
data _null_;
cut1 = &amp;amp;cut1;
cut7 = &amp;amp;cut7;
put cut1= yymmdd10.;
put cut7= yymmdd10.;
run;

/* this is your streamlined code */
data EA1_2;
set EA1_1;
length TimeSinceDiagnosis $7.;
if diagnosis_dt &amp;gt; &amp;amp;cut1. then TimeSinceDiagnosis = '&amp;lt;1yr';
else if diagnosis_dt  &amp;gt; &amp;amp;cut7. then TimeSinceDiagnosis = '2-7yrs';
else TimeSinceDiagnosis = '&amp;gt;=8yrs';
run;
/* note that the else-if makes some conditions redundant */&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Nov 2020 11:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Urgent-help-Creating-a-categorical-variable-out-of-a-date/m-p/699105#M25578</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-16T11:31:03Z</dc:date>
    </item>
  </channel>
</rss>

