<?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 create a new variable for numeric variable and get survival time? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-new-variable-for-numeric-variable-and-get/m-p/893489#M352988</link>
    <description>&lt;P&gt;Why is ID 5 shown as "Depression" and not "Recurrent"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How is exp_survtime calculated from this data? Please explain in words.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does this sentence have to do with solution to the problem? "The study period between depression 9 and depression 10 was two years."&lt;/P&gt;</description>
    <pubDate>Sun, 10 Sep 2023 18:06:18 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-09-10T18:06:18Z</dc:date>
    <item>
      <title>How to create a new variable for numeric variable and get survival time?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-new-variable-for-numeric-variable-and-get/m-p/893487#M352986</link>
      <description>&lt;P&gt;Hi SAS community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope you are doing well. I'm studying recurrent depression risk factors using a dataset with 'ID' and 'Depression9-Depression15' variables. The study period between depression 9 and depression 10 was two years. I want to categorize outcomes as 'recurrent,' 'depression,' or 'no depression.' 'Recurrent' means experiencing depression twice. Notably, 'Depression9' participants didn't have depression. How can I create this outcome and calculate survival time in these columns? Thanks for your help!&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 ID (depression9-depression15) (:1.) expected_outcome :$&amp;amp;13. exp_Survtime ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0 1 0 1 . . . Recurrent 6&lt;BR /&gt;2 0 0 1 0 . 1 . Recurrent 10&lt;BR /&gt;3 0 0 0 0 0 0 0 No Depression 12&lt;BR /&gt;4 0 . 1 0 1 . . Recurrent 8&lt;BR /&gt;5 0 . . 1 1 1 1 Depression 6&lt;BR /&gt;6 0 1 . . 0 1 . Recurrent 10&lt;BR /&gt;7 0 . 1 . . 0 1 Recurrent 12&lt;BR /&gt;8 0 0 . . . 0 . No Depression 10&lt;BR /&gt;9 0 . 1 1 0 . . Depression 4&lt;BR /&gt;10 0 1 0 1 1 0 1 Recurrent 6&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Sep 2023 17:53:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-new-variable-for-numeric-variable-and-get/m-p/893487#M352986</guid>
      <dc:creator>nwang5</dc:creator>
      <dc:date>2023-09-10T17:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new variable for numeric variable and get survival time?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-new-variable-for-numeric-variable-and-get/m-p/893489#M352988</link>
      <description>&lt;P&gt;Why is ID 5 shown as "Depression" and not "Recurrent"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How is exp_survtime calculated from this data? Please explain in words.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does this sentence have to do with solution to the problem? "The study period between depression 9 and depression 10 was two years."&lt;/P&gt;</description>
      <pubDate>Sun, 10 Sep 2023 18:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-new-variable-for-numeric-variable-and-get/m-p/893489#M352988</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-10T18:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new variable for numeric variable and get survival time?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-new-variable-for-numeric-variable-and-get/m-p/893490#M352989</link>
      <description>Thank you for quick response and your question. &lt;BR /&gt;&lt;BR /&gt;ID 5 did not recover after depression 6, so it's categorized as having depression. &lt;BR /&gt;&lt;BR /&gt;The survival time was defined as the duration from depression 9 to the first occurrence of depression, resulting in a survival time of six years for ID 5.&lt;BR /&gt;&lt;BR /&gt;For recurrent depression, let's look at ID 1 as an example. ID 1 experienced depression in depression 10, recovered in depression 11, and then had another episode of depression in depression 12. Therefore, ID 1 is classified as recurrent. The time gap between each depression episode is two years. The time difference between depression 12 and depression 9 is 3 times 2, which equals 6 years.</description>
      <pubDate>Sun, 10 Sep 2023 18:16:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-new-variable-for-numeric-variable-and-get/m-p/893490#M352989</guid>
      <dc:creator>nwang5</dc:creator>
      <dc:date>2023-09-10T18:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new variable for numeric variable and get survival time?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-new-variable-for-numeric-variable-and-get/m-p/893491#M352990</link>
      <description>&lt;P&gt;Thank you. None of this was stated in the original problem statement, making solutions based upon the original problem statement impossible. It would be a very good idea for you to include all relevant information from now on in your original problem statement, you will get faster and better answers that way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
    value outf 0='No Depression' 1='Depression' 2='Recurrent';
run;
data want;
    set have(drop=exp:);
    array depr depression:;
	first_occurence_of_1=whichn(1,of depression:);
	exp_survtime=(first_occurence_of_1-1)*2;
	zero_flag=0;
	one_flag=0;
	if sum(of depression:)=0 then expected_outcome=0;
	else do i=(first_occurence_of_1+1) to dim(depr);
	    if depr(i)=0 then zero_flag=i;
	    if depr(i)=1 then one_flag=i;
	    if zero_flag&amp;gt;0 and one_flag&amp;gt;zero_flag then do;
	        expected_outcome=2;
	        leave;
        end;
        if one_flag&amp;gt;0 and zero_flag=0 then do;
            expected_outcome=1;
            leave;
        end;
    end;
    drop i one_flag zero_flag;
    format expected_outcome outf.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Sep 2023 18:40:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-new-variable-for-numeric-variable-and-get/m-p/893491#M352990</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-10T18:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new variable for numeric variable and get survival time?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-new-variable-for-numeric-variable-and-get/m-p/893494#M352992</link>
      <description>&lt;P&gt;Thank you for providing a &lt;STRIKE&gt;working&lt;/STRIKE&gt; data step for code testing.&lt;/P&gt;
&lt;P&gt;Edit: (On second look, it's not working as submitted - please see note at bottom.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What OUTCOME is assigned if a person experiences depression only once,&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;as the last depression value?&lt;/LI&gt;
&lt;LI&gt;as a middle value?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;---------------------------------------&lt;/P&gt;
&lt;P&gt;The program submitted for sample data was apparently not tested.&amp;nbsp; It generates only 8 obs from 10 records, as submitted, and generates this log message:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;More space is needed between expected_outcome and exp_survtime, per below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID (depression9-depression15) (:1.) expected_outcome :$&amp;amp;13. exp_Survtime ;
datalines;
1 0 1 0 1 . . . Recurrent       6
2 0 0 1 0 . 1 . Recurrent      10
3 0 0 0 0 0 0 0 No Depression  12
4 0 . 1 0 1 . . Recurrent       8
5 0 . . 1 1 1 1 Depression      6
6 0 1 . . 0 1 . Recurrent      10
7 0 . 1 . . 0 1 Recurrent      12
8 0 0 . . . 0 . No Depression  10
9 0 . 1 1 0 . . Depression      4
10 0 1 0 1 1 0 1 Recurrent      6
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Sep 2023 20:58:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-new-variable-for-numeric-variable-and-get/m-p/893494#M352992</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-09-10T20:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new variable for numeric variable and get survival time?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-new-variable-for-numeric-variable-and-get/m-p/893511#M352999</link>
      <description>&lt;P&gt;This code reproduces the results described.&amp;nbsp; But, it assigns a single depression episode as "Depression" in the absence of specific instructions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID (depression9-depression15) (:1.) expected_outcome :$&amp;amp;13. exp_Survtime ;
datalines;
1 0 1 0 1 . . . Recurrent       6
2 0 0 1 0 . 1 . Recurrent      10
3 0 0 0 0 0 0 0 No Depression  12
4 0 . 1 0 1 . . Recurrent       8
5 0 . . 1 1 1 1 Depression      6
6 0 1 . . 0 1 . Recurrent      10
7 0 . 1 . . 0 1 Recurrent      12
8 0 0 . . . 0 . No Depression  10
9 0 . 1 1 0 . . Depression      4
10 0 1 0 1 1 0 1 Recurrent      6
run;

data want (drop=i _:);
  set have;

  array dep {*} depression: ;
  /*With 0 and . as word separators, count N of "words" in the concatenated depression sequence*/
  _n_depression_cycles=countw(cat(of dep{*}),'0.');

  if _n_depression_cycles=0 then do;
    outcome='No Depression';
    do i=dim(dep) to 1 by -1 until(dep{i}=0); *Find last zero **;
    end;
  end;
  else if _n_depression_cycles=1 then do;
    outcome='Depression';
    do i=1 to dim(dep) until (dep{i}=1);      *Find first 1 ;
    end;
  end;
  else do;
    outcome='Recurrent' ;                     *Find start of recurrance;
    do i=whichn(1,of dep{*})+2 to dim(dep) until (dep{i}=1 and dep{i-1}^=1);
    end;
  end;

  survtime=2*(i-1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Sep 2023 00:40:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-new-variable-for-numeric-variable-and-get/m-p/893511#M352999</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-09-11T00:40:18Z</dc:date>
    </item>
  </channel>
</rss>

