04-10-2018 04:44 PM
I have input file of 129632 records that needs to be split on the basis of start date and end date into two file . I have calculated those Date in my first part .I want to use those date just as variable so that the CPU time decrease. Below code is also working but the output is adding Date with all the input record as observation and hence increase the total turn around time.
IF _N_ = 1 THEN DO;
END_DATE = TODAY();
CURRENT_DAY = DAY(TODAY());
START_DATE=TEMP_DATE + CURRENT_DAY - 1;
RETAIN START_DATE ;
INFILE INPUT1 ;--FILE HAS 129632 RECORDS
INPUT @9 CODEDT $CHARZB10.;
IF CODE_DATE >= START_DATE AND CODE_DATE <= END_DATE THEN PUT _INFILE_;
IF CODE_DATE < START_DATE THEN PUT _INFILE_;
04-10-2018 07:08 PM
data DATE_CHK; retain END_DATE START_DATE; drop END_DATE START_DATE CODEDT; format CODE_DATE date9.; if _N_ = 1 then do; END_DATE = today(); CURRENT_DAY = day(today()); TEMP_DATE = intnx('month',END_DATE,-3); START_DATE = TEMP_DATE + CURRENT_DAY - 1; end; infile INPUT1; input @9 CODEDT $charzb10.; CODE_DATE = input(CODEDT,yymmdd10.); if CODE_DATE >= START_DATE and CODE_DATE <= END_DATE then do; file ACTIVE; put _INFILE_; end; if CODE_DATE < START_DATE then do; file INACTIVE; put _INFILE_; end; run;
1. All uppercase is hard to read
2. data _null_ ; will further speed things up, if you only need the new flat files
3. Moving the file statements in the do block should save time
4. 100k records should take no time at all
04-17-2018 08:18 PM
129632 records is low volume so not sure why you care that much about resources unless that's a process which you run every 5 minutes or so.
To consume less resources:
- Use a Data _NULL_; step
- Use if... then... ELSE as you're either writing a record to the active or the inactive file but not both.
And last but not least: If changing between two output files don't you need to use the MOD option in your file statements. Does your code actually work?
04-17-2018 08:36 PM