Fri Nov 26, 2021 11:56 pm
Login Register Lost Password? Contact Us


Creating a sample with thousands of criteria.

Questions around writing code and queries

Tue Aug 03, 2021 2:12 pm Change Time Zone

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.
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: 442
Joined: Sat Oct 01, 2011 7:26 pm

Wed Aug 04, 2021 8:10 am Change Time Zone

AH Of Course

Just a inner JOIN against a dataset with list of dates with KEEP(n) as a qualifier.
Allan
 
Posts: 442
Joined: Sat Oct 01, 2011 7:26 pm

Mon Aug 09, 2021 5:45 pm Change Time Zone

Allan,

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;

:D

HTH,

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1604
Joined: Wed Oct 26, 2011 7:40 pm


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron