<?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: JMP Data Arrangement in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JMP-Data-Arrangement/m-p/410372#M66010</link>
    <description>&lt;P&gt;Does the patient have only one 0 disease value before the first 1 disease value or can there be multiple 0 values before the first 1?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit:&lt;/P&gt;&lt;P&gt;Here are two possible solutions depending on the data:&lt;/P&gt;&lt;P&gt;In the first one sort the data first by patientid and time, then create two formula columns and check should have the information you are interested in. There might be some edge cases this will miss (like the last row).&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = New Table("Untitled",
	Add Rows(14),
	Compress File When Saved(1),
	New Column("PatientID",
		Numeric,
		"Nominal",
		Format("Best", 12),
		Set Values([1, 1, 1, 1, 2, 2, 1, 3, 3, 3, 3, 1, 1, 1]),
		Set Display Width(62)
	),
	New Column("Status",
		Numeric,
		"Nominal",
		Format("Best", 12),
		Set Values([0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0]),
		Set Display Width(50)
	),
	New Column("Time",
		Numeric,
		"Continuous",
		Format("m.d.y h:m", 19),
		Input Format("m.d.y h:m"),
		Set Values(
			[3660718210, 3660718260, 3660718320, 3660718380, 3660718440, 3660718500, 3660718560, 3660718620, 3660718680,
			3660718740, 3660718800, 3660718860, 3660718920, 3660718920]
		)
	)
);


// Sort data table
dt &amp;lt;&amp;lt; Sort(By(:PatientID, :Time), Replace Table, Order(Ascending, Ascending));

//add formula columns
dt &amp;lt;&amp;lt; New Column("CumSumOfStatus",
	Numeric,
	"Continuous",
	Format("Best", 12),
	Formula(Col Cumulative Sum(:Status, :PatientID))
);

//add formula columns
dt &amp;lt;&amp;lt; New Column("Check",
	Numeric,
	"Continuous",
	Format("Best", 12),
	Formula(
		If(Row() == 1, :Status);
		If(Lag(:CumSumOfStatus, -1) == 1 &amp;amp; Lag(:PatientID) == :PatientID,
			1,
			0
		);
	)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1629177425699.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/35095i7DC934F861B828EF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1629177425699.png" alt="jthi_0-1629177425699.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Second one is expecting that patientid has only one 0 status before first 1 status which allows you to just get minimum times for both statuses using summary:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//If only one 0 before 1
dt2 = New Table("Untitled",
	Add Rows(11),
	Compress File When Saved(1),
	New Column("PatientID",
		Numeric,
		"Nominal",
		Format("Best", 12),
		Set Values([1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3]),
		Set Display Width(62)
	),
	New Column("Status",
		Numeric,
		"Nominal",
		Format("Best", 12),
		Set Values([0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0]),
		Set Display Width(50)
	),
	New Column("Time",
		Numeric,
		"Continuous",
		Format("m.d.y h:m", 19),
		Input Format("m.d.y h:m"),
		Set Values(
			[3660718380, 3660718560, 3660718860, 3660718920, 3660718920, 3660718440, 3660718500, 3660718620, 3660718680,
			3660718740, 3660718800]
		)
	)
);

dt &amp;lt;&amp;lt; Summary(Group(:PatientID), Min(:Time), Subgroup(:Status), Freq("None"), Weight("None"));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Aug 2021 05:18:49 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2021-08-17T05:18:49Z</dc:date>
    <item>
      <title>JMP Data Arrangement</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-Data-Arrangement/m-p/410355#M66009</link>
      <description>&lt;P class="p2"&gt;&lt;SPAN class="s1"&gt;Hi all, I have a rather complex question on how to arrange data in jmp.&amp;nbsp;&lt;/SPAN&gt;Basically I am looking at patient follow-up and how long it will take them to develop a particular disease. I have 3 columns of data. Column 1 is each patient’s identifiable code. Nearly all patients are listed multiple times in column 1 as they had multiple follow-ups. Column 2 is a binary code on whether or not they have the disease (0=no disease, 1=disease) at that follow-up date. And column 3 is their follow-up date.&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;What I want to do is isolate when column 2 changes from 0—&amp;gt;1 for the first time for each patient (this can happen multiple times for each patient since they could have been treated and cured, thus resetting the disease back to 0, so I just want the first time 0--&amp;gt;1). I need both values&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;because I am taking the average of their corresponding follow-up dates to approximate the date they were positive for the disease. The rest of the data I do not need.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: inherit;"&gt;I hope this makes sense, please let me know if I need to elaborate. Sorry in advance if this is not what JMP is meant to do. Thanks!&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:35:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-Data-Arrangement/m-p/410355#M66009</guid>
      <dc:creator>jmpquestions123</dc:creator>
      <dc:date>2023-06-10T23:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: JMP Data Arrangement</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-Data-Arrangement/m-p/410372#M66010</link>
      <description>&lt;P&gt;Does the patient have only one 0 disease value before the first 1 disease value or can there be multiple 0 values before the first 1?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit:&lt;/P&gt;&lt;P&gt;Here are two possible solutions depending on the data:&lt;/P&gt;&lt;P&gt;In the first one sort the data first by patientid and time, then create two formula columns and check should have the information you are interested in. There might be some edge cases this will miss (like the last row).&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = New Table("Untitled",
	Add Rows(14),
	Compress File When Saved(1),
	New Column("PatientID",
		Numeric,
		"Nominal",
		Format("Best", 12),
		Set Values([1, 1, 1, 1, 2, 2, 1, 3, 3, 3, 3, 1, 1, 1]),
		Set Display Width(62)
	),
	New Column("Status",
		Numeric,
		"Nominal",
		Format("Best", 12),
		Set Values([0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0]),
		Set Display Width(50)
	),
	New Column("Time",
		Numeric,
		"Continuous",
		Format("m.d.y h:m", 19),
		Input Format("m.d.y h:m"),
		Set Values(
			[3660718210, 3660718260, 3660718320, 3660718380, 3660718440, 3660718500, 3660718560, 3660718620, 3660718680,
			3660718740, 3660718800, 3660718860, 3660718920, 3660718920]
		)
	)
);


// Sort data table
dt &amp;lt;&amp;lt; Sort(By(:PatientID, :Time), Replace Table, Order(Ascending, Ascending));

//add formula columns
dt &amp;lt;&amp;lt; New Column("CumSumOfStatus",
	Numeric,
	"Continuous",
	Format("Best", 12),
	Formula(Col Cumulative Sum(:Status, :PatientID))
);

//add formula columns
dt &amp;lt;&amp;lt; New Column("Check",
	Numeric,
	"Continuous",
	Format("Best", 12),
	Formula(
		If(Row() == 1, :Status);
		If(Lag(:CumSumOfStatus, -1) == 1 &amp;amp; Lag(:PatientID) == :PatientID,
			1,
			0
		);
	)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1629177425699.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/35095i7DC934F861B828EF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1629177425699.png" alt="jthi_0-1629177425699.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Second one is expecting that patientid has only one 0 status before first 1 status which allows you to just get minimum times for both statuses using summary:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//If only one 0 before 1
dt2 = New Table("Untitled",
	Add Rows(11),
	Compress File When Saved(1),
	New Column("PatientID",
		Numeric,
		"Nominal",
		Format("Best", 12),
		Set Values([1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3]),
		Set Display Width(62)
	),
	New Column("Status",
		Numeric,
		"Nominal",
		Format("Best", 12),
		Set Values([0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0]),
		Set Display Width(50)
	),
	New Column("Time",
		Numeric,
		"Continuous",
		Format("m.d.y h:m", 19),
		Input Format("m.d.y h:m"),
		Set Values(
			[3660718380, 3660718560, 3660718860, 3660718920, 3660718920, 3660718440, 3660718500, 3660718620, 3660718680,
			3660718740, 3660718800]
		)
	)
);

dt &amp;lt;&amp;lt; Summary(Group(:PatientID), Min(:Time), Subgroup(:Status), Freq("None"), Weight("None"));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 05:18:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-Data-Arrangement/m-p/410372#M66010</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-08-17T05:18:49Z</dc:date>
    </item>
  </channel>
</rss>

