Choose Language Hide Translation Bar
Highlighted
djmomo
Level I

Selecting data for past X number of days

I have a data set that contains past 60 days of data and I want just past 7 days of data. Data column name "OUT_DATE" in the format of   MM/DD/YYY HH:MM:SS AM/PM. Date is not sorted and in random order.

 

I found the following discussion answered by super user "txnelson" (https://community.jmp.com/t5/Discussions/Date-function-in-jsl/td-p/57122) and did my script as below

 

dt=Open("Report.csv");// Opening the main datafile
P7D = dt << select where( today() - In Days( 7 ) < :OUT_DATE );// Selecting past 7 days data and assigning it to P7D
P7D << Save("P7D.csv");// Save P7D as csv

But my output file "P7D.csv" has an exact copy of the "Report.csv".

 

 

How can I store only past 7 days of data in P7D?

3 REPLIES 3
Highlighted
txnelson
Super User

Re: Selecting data for past X number of days

Selection of given rows does not affect the saving.  The easiest way to do that, is to create a subset of the data, based upon the selection, and then save that subset. (The below is corrected code: see @gzmorgan0 )

names default to here(1);
dt=Open("Report.csv");// Opening the main datafile
dt << select where( today() - In Days( 7 ) < :OUT_DATE );// Selecting past 7 days data and assigning it to P7D
P7D = dt << subset(invisible, selected columns(0), selected rows(1));
P7D << Save("P7D.csv");// Save P7D as csv
close( P7D, nosave);

 

Jim
Highlighted
gzmorgan0
Super User

Re: Selecting data for past X number of days

Just a simple correction, @txnelson nice solution is missing an equal sign. Line 4 should be

P7D = dt << subset(invisible, selected columns(0), selected rows(1));

 

Highlighted
txnelson
Super User

Re: Selecting data for past X number of days

Thanks for the catch

Jim
Article Labels

    There are no labels assigned to this post.