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.
Please suggest.
Code :
DATA DATE_CHK;
IF _N_ = 1 THEN DO;
END_DATE = TODAY();
RETAIN END_DATE;
CURRENT_DAY = DAY(TODAY());
TEMP_DATE=INTNX('MONTH',END_DATE,-3);
START_DATE=TEMP_DATE + CURRENT_DAY - 1;
RETAIN START_DATE ;
END;
INFILE INPUT1 ;--FILE HAS 129632 RECORDS
INPUT @9 CODEDT $CHARZB10.;
CODE_DATE=INPUT(CODEDT,YYMMDD10.);
FILE ACTIVE;
IF CODE_DATE >= START_DATE AND CODE_DATE <= END_DATE THEN PUT _INFILE_;
FILE INACTIVE;
IF CODE_DATE < START_DATE THEN PUT _INFILE_;
RUN;
Just name the variables that you want in your output dataset in a KEEP statement.
For example:
KEEP code_date start_date end_date;
Like this?
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
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?
We are running out of options here.
@Patrick is right that adding else will shave a few μs, but that's it.
How much CPU are you using? How much are you aiming for?
Show us the full log please, with options source and fullstimer turned on.
You may also be able to save peanuts by removing 2 lines of code:
START_DATE = intnx('month', END_DATE, -3, 's');
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.