cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
SDF1
Super User

JSL code & Summarize help

Hi JMP community,

 

  JMP Pro v17.

 

  I  have a script that had been working last month, but doesn't appear to be working anymore. I have a data table where one column is named :Date (see attached data table). The following script is supposed to summarize the data table by the Year( ) of :Date and generate a list of years for the variable "yrs".

Summarize( dt, yrs = By( Year( :Date ) ) );

  For example, it is supposed to return a list of dates like {"2022", "2023", "2024"} and so on, because the Year( ) command is supposed to extract out just the year value from the :Date column, however it doesn't.

 

  If you remove the Year( ) command around :Date and run it like this:

Summarize( dt, yrs = By( :Date ) );

  The result is a list of all the individual dates, here's an excerpt:

 

{"09/29/0263", "01/30/1930", "02/11/1955", "05/03/2002", "08/13/2002", "10/19/2002",
"01/01/2021", "01/02/2021", "01/06/2021", "01/18/2021", "01/30/2021", "02/12/2021",
"02/13/2021", "02/15/2021", "03/26/2021", "03/27/2021", "03/28/2021", "03/30/2021",
"04/23/2021", "04/24/2021", "04/25/2021",}

 

  There are some mistyped dates, but this can be ignored right now.

 

  I don't actually want all the individual dates, I just want a list of all the years. Unfortunately, when I try to execute yr = Year( :Date), then I get a null/empty variable for yr. This ends up not being able to be evaluated by the next By( ) command around it in the original JSL. I don't know if I need

 

  What I find strange is that about a month ago when I was building this code, it seemed to work just fine, but now it's not functioning like it was.

 

  I'm sure I'm missing something simple that's causing this problem, but I can't figure out what it is. Or, I'm thinking about the Summarize( ) and/or how it uses the By( ) group in it.

 

Thanks for any thoughts/feedback!,
DS

 

10 REPLIES 10
jthi
Super User

Re: JSL code & Summarize help

I don't think you can do that with Summarize but you could use Summary with transform column if you don't want to create new column to your table

Names Default To Here(1);

dt = Open("$DOWNLOADS/Date.jmp");

dt_summary = dt << Summary(
	Group(Transform Column("Year", Formula(Year(:Date)))),
	Freq("None"),
	Weight("None"),
	Link to original data table(0),
	output table name("Summary of Date grouped by Year"),
	Private
);

years = dt_summary[0, 1];
Close(dt_summary, no save);

Show(years);

 

-Jarmo

Recommended Articles