BookmarkSubscribeRSS Feed
WFC2013
Fluorite | Level 6

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;                                                                  

7 REPLIES 7
PGStats
Opal | Level 21

Just name the variables that you want in your output dataset in a KEEP statement.

 

For example:

 

KEEP code_date start_date end_date;

PG
WFC2013
Fluorite | Level 6
Thanks
ChrisNZ
Tourmaline | Level 20

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

 

 

 

WFC2013
Fluorite | Level 6
Thanks , but still the CPU is not decreasing.
Patrick
Opal | Level 21

@WFC2013

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?

ChrisNZ
Tourmaline | Level 20

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.

 

ChrisNZ
Tourmaline | Level 20

You may also be able to save peanuts by removing 2 lines of code:

  START_DATE  = intnx('month', END_DATE, -3, 's');                                

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 815 views
  • 2 likes
  • 4 in conversation