BookmarkSubscribeRSS Feed
Nipun22
Obsidian | Level 7

Like if i compare IF and WHERE etc etc.

 

which statement or option has role in compilation and execution phase?

4 REPLIES 4
Ksharp
Super User
If I was right, IF statement would get faster if you have a very big table, otherwise WHEN statement get faster.
SASKiwi
PROC Star

Try your use case yourself. Sometimes IF is faster / better and sometimes WHERE. It all depends on what you are doing.

whymath
Lapis Lazuli | Level 10

You can search that if anyone do some tests and post a conclusion, like you may see someone compares different ways to conduct table lookup: Table Look-Up by Direct Addressing: Key-Indexing -- Bitmapping -- Hashing (It's really a great paper)

 

Or you can take some tests by yourself.

There are `find()`, `index()` and `prxmatch()` to search specified string, which one is faster? Here is how I test:

 

%macro prog_runtime(prog,reps=20,title=Input Prog);
%local _Rep_ _Start_ _End_ _Dur_ _TimeRec_ _SumTime_ _AvgTime_ _MedTime_;

/*Record time consuming of input prog*/
%let _SumTime_ = 0;
%let _TimeRec_ = ;

%do _Rep_ = 1 %to &Reps.;
  %let _Start_ = %sysfunc(datetime());
  %unquote(&Prog.);
  %let _End_ = %sysfunc(datetime());
  %let _Dur_ = %sysevalf(&_End_. - &_Start_.);
  %let _TimeRec_ = &_TimeRec_. &_Dur_.;
  %let _SumTime_ = %sysevalf(&_SumTime_. + &_Dur_.);
%end;

/*Compute median and mean time consuming*/
%let _AvgTime_ = %sysevalf(&_SumTime_/&Reps.);
%let _MedTime_ = %sysfunc(median(%sysfunc(tranwrd(%cmpres(&_TimeRec_.),%str( ),%str(,))) ));

/*Report test result*/
%put ****************************************;
%put Summary of Run Time of &title.;
%put Sum of Run Time:    %sysfunc(putn(&_SumTime_.,20.4));
%put Mean of Run Time:   %sysfunc(putn(&_AvgTime_.,20.4));
%put Median of Run Time: %sysfunc(putn(&_MedTime_.,20.4));
%put ;
%mend;

option nonotes nosource;
%Prog_RunTime(%nrstr(
data _null_;
  x = 'Text with many blanks.';
  do i = 1 to 1e7;
    y = index(x,'many');
  end;
run;
),title=index());

%Prog_RunTime(%nrstr(
data _null_;
  x = 'Text with many blanks.';
  do i = 1 to 1e7;
    y = find(x,'many');
  end;
run;
),title=find());

%Prog_RunTime(%nrstr(
data _null_;
  x = 'Text with many blanks.';
  do i = 1 to 1e7;
    y = prxmatch('/many/',x);
  end;
run;
),title=prxmatch());
option notes source;

Here is the test result:

****************************************
Summary of Run Time of index()
Sum of Run Time:                  2.2940
Mean of Run Time:                 0.1147
Median of Run Time:               0.1140

****************************************
Summary of Run Time of find()
Sum of Run Time:                  2.8360
Mean of Run Time:                 0.1418
Median of Run Time:               0.1420

****************************************
Summary of Run Time of prxmatch()
Sum of Run Time:                  8.2410
Mean of Run Time:                 0.4121
Median of Run Time:               0.4115

So, if differences of these three functions are ignored, I always choose `index()`.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 4 replies
  • 529 views
  • 3 likes
  • 5 in conversation