BookmarkSubscribeRSS Feed
ChrisNZ
Tourmaline | Level 20
Hi Peter,

>That sounds like replacing input strings or values with a randomly distributed ...

The values don't matter here, this is about methods of testing. Tested values or results could be strings in this case.

>This will be true when there are 4 tests for 1 function, and perhaps above 10:1.
I guess the threshhold is platform dependant.

Indeed. If a function is 10 times slower than a test, having more than 10 tests makes the function appealing again (and starts cluttering the data step too). As usual, one has to do one's home work depending on the particular circumstances. I suspect testing long strings would be more time consuming testing than short ones for example.

The main thing imho though, is that unless these tests are run millions of times, legibility matters most (whatever this means to each of us :o).

These runs give an overwhelming speed advantage to formats:

[pre]
%macro loop; * create a 2000-else-if test;
%do i=1 %to 2000;
else if A<&i then B=&i;
%end;
%mend;
data _null_; * 1 test before match 0.09s;
A=1;
do I=1 to 1e6;
if A<0 then B=1;
%loop
end;
run;
data _null_; * 1000 tests before match 7.2s;
A=1e3;
do I=1 to 1e6;
if A<0 then B=1;
%loop
end;
run;


%macro loop; * create a 2000-when test;
%do i=1 %to 2000;
when(&i) B=&i;
%end;
%mend;
data _null_; * select clause 17s;
A=1;
do I=1 to 1e6;
select(I);
%loop
otherwise;
end;
end;
run;
data _null_; * select clause 17s;
A=1e3;
do I=1 to 1e6;
select(I);
%loop
otherwise;
end;
end;
run;

proc format ; * create a 2000-entry format;
value test
%macro loop;
%do i=1 %to 2000;
&i="&i"
%end;
%mend;
%loop;
data _null_; * formats 0.09s;
A=1e3;
do I=1 to 1e6;
B=input(put(A,test.),32.);
end;
run;[/pre]
Ksharp
Super User
Hi.Chris
Do you mean that proc format is the most efficient way for judge conditions?
What about some other people? Peter.C?


Ksharp
Peter_C
Rhodochrosite | Level 12
no single approach suits all situations
Ksharp
Super User
Haha.
Peter.C
Your words are too ambiguous , which can suit any situation.


Ksharp
Peter_C
Rhodochrosite | Level 12
Ksharp

I think the original poster's question has been answered
"there is benefit from having ELSE among IF tests"

My answer is not "ambiguous" but neccessary a caution;
as I think there is no generally "best solution" because I think the "situation" (
data volumes,
IF complexity,
need for support/change-management by "others"
) are too important to ignore
but these allways vary

imho
peterC
Ksharp
Super User
Peter.C
I agree with what you said.
But as my experience of processing data, proc format is actually to have less time.Namely I agree with Chris too.

:-)


Best Regards
Ksharp
ChrisNZ
Tourmaline | Level 20
> no single approach suits all situations

I agree:

>As usual, one has to do one's home work depending on the particular circumstances
>The main thing imho though, is that unless these tests are run millions of times, legibility matters most

It would be as silly to never use formats as to never use tests in the situation discussed here.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 21 replies
  • 4571 views
  • 0 likes
  • 9 in conversation