I would like to have a package method output a record to the callers output.
If possible, I can't seem to locate the 'type' that is needed to specify a dataset argument.
Consider this simple example (that does not work)
proc ds2 ; package MyComplicatedPackage / overwrite=yes ; method DoComplicatedRecursiveThings (output aDataset, double _zzz) ; aDataset.zzz = _zzz ; output aDataset ; end ; endpackage ; data foo / overwrite=yes ; declare double zzz ; declare package MyComplicatedPackage mcp() ; method run () ; mcp.DoComplicatedRecursiveThings(foo, 1234) ; end ; enddata ; run ; quit ;
If this was working code, it would create an output data set named foo
foo: zzz ---- 1234
A DS2 method parameter must be one of the supported DS2 data types. DATASET is not a valid datatype. You can use an output statement in the package method to write a row to the dataset that has already been specified in the calling data program.
proc ds2 ;
package MyComplicatedPackage / overwrite=yes ;
/* IN_OUT parameters are passed by reference. When this method is called,
you must specify a variable NAME for the parameter instead of a value.
The value of the variable becomes accessible to, and can be modified by
any of the package methods. */
method DoComplicatedRecursiveThings (in_out double _z) ;
/* Change the value to the square of the original */
_z=_z**2;
/* Output the result to the calling program's data set */
output;
end ;
endpackage ;
data foo / overwrite=yes ;
declare double zzz ;
declare package MyComplicatedPackage mcp() ;
method run () ;
/* Set the initial value of zzz */
zzz=1234;
/* Modify the value and output using the pacakge method */
mcp.DoComplicatedRecursiveThings(zzz) ;
end ;
enddata ;
run ;
quit;
Results:
Obs | zzz |
---|---|
1 | 1522756 |
I hope this helps.
A DS2 method parameter must be one of the supported DS2 data types. DATASET is not a valid datatype. You can use an output statement in the package method to write a row to the dataset that has already been specified in the calling data program.
proc ds2 ;
package MyComplicatedPackage / overwrite=yes ;
/* IN_OUT parameters are passed by reference. When this method is called,
you must specify a variable NAME for the parameter instead of a value.
The value of the variable becomes accessible to, and can be modified by
any of the package methods. */
method DoComplicatedRecursiveThings (in_out double _z) ;
/* Change the value to the square of the original */
_z=_z**2;
/* Output the result to the calling program's data set */
output;
end ;
endpackage ;
data foo / overwrite=yes ;
declare double zzz ;
declare package MyComplicatedPackage mcp() ;
method run () ;
/* Set the initial value of zzz */
zzz=1234;
/* Modify the value and output using the pacakge method */
mcp.DoComplicatedRecursiveThings(zzz) ;
end ;
enddata ;
run ;
quit;
Results:
Obs | zzz |
---|---|
1 | 1522756 |
I hope this helps.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.