Debugging DS2

Reply
Occasional Contributor
Posts: 15

Debugging DS2

Hi all

I am trying to convert a data step into a DS2 data step since I am interested in the threading functionality of DS2.

However I do get the following errors when running the DS2 code:

ERROR: Invalid argument to function RAND.

ERROR: Invalid argument to function RAND.

ERROR: Float divide by zero

ERROR: General error

So I am wondering why there are no "lines" associated to the error messages.

How does one debug DS2 code? The program I am running uses the rand function in probably 50 places.

If anyone has performance comparison of DS2 versus data step that would be interesting as well. I my case I am running a simulation (which is one data step with a do loop). This can be done in a "normal" data step (which can then be parallelized by running multiple SAS instances). However I thought it might be neater to have it in DS2 where I do not need to invoke multiple SAS instances (or use MP Connect).

My code looks roughly like the following (I note that here I am not yet using threads):

Thanks.

data simtest(overwrite=yes);

dcl double a i iteration;

/*some more declarations go here*/

dcl package pkg p();

method init();

end;

method run();

a=streaminit(123);

do iteration = 1 to 10;

     /*here is the main part of the code*/

x=rand('BINOMIAL',1/20,2000);

     output; /*tmp_lib.part&threadId.;*/

end; *Iterations;

end;/*run method*/

enddata;

run; quit;

SAS Employee
Posts: 104

Re: Debugging DS2

DS2 generally reports line numbers for syntax errors (compile time errors) but not for execution time errors (like divide by zero)

Does one of your RAND function calls use a computed value for the second argument? In your sample code I see: x=rand('BINOMIAL',1/20,2000);

If instead the actual code was something like: x=rand('BINOMIAL',1/var1,2000); and the value of var1 was 0 or missing, you would get errors similar to hose you reported.

I tested with this code:

proc ds2 ;

    data simtest(overwrite=yes);

        dcl double a i x var1;

        method init();

           var1=4;

        end;

        method run();

            a=streaminit(123);

            do i=1 to 5;

                x=rand('BINOMIAL', 1/var1, 2000);

                var1=var1-1;

                output;

            end;

        end;

    enddata;

    run;

quit;

and got the expected errors:

ERROR: Float divide by zero

ERROR: General error

So to find the error, look for RAND calls that use computed values.

Hope this helps!

Mark

Ask a Question
Discussion stats
  • 1 reply
  • 478 views
  • 0 likes
  • 2 in conversation