<?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 do I Create a Column using &amp;quot;IF&amp;quot; and &amp;quot;Contains&amp;quot; in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-do-I-Create-a-Column-using-quot-IF-quot-and-quot-Contains/m-p/213638#M42736</link>
    <description>&lt;P&gt;WOW!&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 19 Jun 2019 01:38:44 GMT</pubDate>
    <dc:creator>ileshem</dc:creator>
    <dc:date>2019-06-19T01:38:44Z</dc:date>
    <item>
      <title>How do I Create a Column using "IF" and "Contains"</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-Create-a-Column-using-quot-IF-quot-and-quot-Contains/m-p/213627#M42734</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a date and time column with "AM" and "PM" in the format.&lt;/P&gt;
&lt;P&gt;Using JSL, I wand to add a new column that will indicate it its a day or night.&lt;/P&gt;
&lt;P&gt;Row with "PM" in the date will input "Day"&lt;/P&gt;
&lt;P&gt;Row with "AM" in the date will input "Night"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I try using the following:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For( i = 1, i &amp;lt;= N Rows( dt ), i++,
If( Contains( :Date[i], "PM" ) ,
:Day/Night[i] = :Day[i]
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it wont work.&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;BR /&gt;);&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 12:34:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-Create-a-Column-using-quot-IF-quot-and-quot-Contains/m-p/213627#M42734</guid>
      <dc:creator>ileshem</dc:creator>
      <dc:date>2019-06-19T12:34:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Create a Column using "IF" and "Contains"</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-Create-a-Column-using-quot-IF-quot-and-quot-Contains/m-p/213637#M42735</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/8850"&gt;@ileshem&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;If your Date column is stored in proper date/time format, it won't actually contain characters, even though it's displayed as such. So, you'll need a function that doesn't look for the AM/PM, but rather can determine if the DateTime indicates a time after 12pm or not. I've attached a table in which I've done this using the following column formula:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Hour( :Time ) &amp;gt;= 12, "Night", "Day")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could adapt this to work as part of your script easily, like below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For( i = 1, i &amp;lt;= N Rows( dt ), i++, 
	If( Hour( :Time[i] ) &amp;gt;= 12,
		:Name( "Day/Night" )[i] = "Night",
		:Name( "Day/Night" )[i] = "Day"
	)
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;These use the Hour() function to pull the hour of the day from the DateTime. Also, in your original JSL, you need to :Name() to reference your column Day/Night, since the special character (a slash) means the column name needs to be quoted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2026"&gt;@jules&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 00:57:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-Create-a-Column-using-quot-IF-quot-and-quot-Contains/m-p/213637#M42735</guid>
      <dc:creator>jules</dc:creator>
      <dc:date>2019-06-19T00:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Create a Column using "IF" and "Contains"</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-Create-a-Column-using-quot-IF-quot-and-quot-Contains/m-p/213638#M42736</link>
      <description>&lt;P&gt;WOW!&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 01:38:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-Create-a-Column-using-quot-IF-quot-and-quot-Contains/m-p/213638#M42736</guid>
      <dc:creator>ileshem</dc:creator>
      <dc:date>2019-06-19T01:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Create a Column using "IF" and "Contains"</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-Create-a-Column-using-quot-IF-quot-and-quot-Contains/m-p/213639#M42737</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/8850"&gt;@ileshem&lt;/a&gt; ,&lt;/P&gt;
&lt;P&gt;All of this syntax is nicely documented in the Scripting Guide.&amp;nbsp; I strongly suggest that you take the time to read this documntation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; Help==&amp;gt;Books==&amp;gt;Scripting Guide&lt;/P&gt;
&lt;P&gt;It will give you the detail you need to make your venturing into JSL much easier.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 01:54:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-Create-a-Column-using-quot-IF-quot-and-quot-Contains/m-p/213639#M42737</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2019-06-19T01:54:25Z</dc:date>
    </item>
  </channel>
</rss>

