Creating a sample with thousands of criteria.
Hi,
I have to create a sample DATASET where there are 'n' records for every day between 20160101 and 20210630 about 2008 days.
Now there are various ways I've thought of doing this.
I could write a MACRO to generate a CHOOSESETS that has a criteria for every day
e.g.
I could SORT by date then ITERATE retaining a counter and just SKIP when inputs counter passes 'n'.
But one feels these are all to complicated and I'm missing a very simple way to do this.
By the way I can error if there are no records for a day by LEFT ONLY join on a datasets of complete date range, so that's not an issue.
Any Ideas?
Allan
I have to create a sample DATASET where there are 'n' records for every day between 20160101 and 20210630 about 2008 days.
Now there are various ways I've thought of doing this.
I could write a MACRO to generate a CHOOSESETS that has a criteria for every day
e.g.
- Code: Select all
x := CHOOESETS(inputDS,date = '20160101' => n
,date = '20160102' => n
etc
I could SORT by date then ITERATE retaining a counter and just SKIP when inputs counter passes 'n'.
But one feels these are all to complicated and I'm missing a very simple way to do this.
By the way I can error if there are no records for a day by LEFT ONLY join on a datasets of complete date range, so that's not an issue.
Any Ideas?
Allan
- Allan
- Posts: 444
- Joined: Sat Oct 01, 2011 7:26 pm
AH Of Course
Just a inner JOIN against a dataset with list of dates with KEEP(n) as a qualifier.
Just a inner JOIN against a dataset with list of dates with KEEP(n) as a qualifier.
- Allan
- Posts: 444
- Joined: Sat Oct 01, 2011 7:26 pm
Allan,
You might also do it this way:
HTH,
Richard
You might also do it this way:
- Code: Select all
IMPORT Std;
Std.Date.Date_t StartDate := 20210101;
Std.Date.Date_t EndDate := 20210110;
n := 10;
nDays := Std.Date.DaysBetween(StartDate,EndDate) + 1;
NumRecs := nDays * n;
Std.Date.Days_t StartDateJ := Std.Date.FromGregorianDate(StartDate);
OutRec := RECORD
Std.Date.Date_t ThisDate;
UNSIGNED1 WhichRec;
STRING10 OtherStuff;
END;
OutRec XF(INTEGER C) := TRANSFORM
Cmod := C % n;
Cday := IF(Cmod <> 0,TRUNCATE(C/10) + 1,TRUNCATE(C/10));
SELF.ThisDate := Std.Date.ToGregorianDate(StartDateJ + (Cday-1));
SELF.WhichRec := IF(Cmod <> 0,Cmod,n);
SELF.OtherStuff := 'junk ' + C;
END;
ds := DATASET(NumRecs,XF(COUNTER));
ds;

HTH,
Richard
- rtaylor
- Community Advisory Board Member
- Posts: 1619
- Joined: Wed Oct 26, 2011 7:40 pm
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: Google [Bot] and 2 guests