Consider using the IN_OUT argument when defining DS2 methods with character arguments


DS2's default parameter passing semantics are pass-by-value. This means that a copy of the parameter is made and the copy is passed to the method, not the original parameter. Any changes to the parameter by the method are made to the copy and not to the original parameter, ensuring that the value of the original parameter is maintained for the caller of the method.

Given the potential size of character variables, the cost of making the copy, in terms of both memory and time, can be great. To avoid this cost, consider using the IN_OUT argument, which causes the parameter to be passed-by-reference. This means that the location or address of the parameter is passed to the method, and a second copy of the parameter is not made. Changes made to the value of the parameter by the method, either intentional or unintentional, are reflected in any reference to the parameter by the caller after the method returns.

For information about related restrictions, requirements, and tips, see the Method statement in the SAS® 9.4 DS2 Language Reference.

This syntax shows the two types of parameter passing:

/* pass-by-value */

method copy_made(char(256) x);

...

end;

/* pass-by-reference */

method no_copy(in_out char x);

...

end;