BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
RichardAD
Quartz | Level 8

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
1 ACCEPTED SOLUTION

Accepted Solutions
SASJedi
Ammonite | Level 13

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.  

Check out my Jedi SAS Tricks for SAS Users

View solution in original post

1 REPLY 1
SASJedi
Ammonite | Level 13

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.  

Check out my Jedi SAS Tricks for SAS Users

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1104 views
  • 2 likes
  • 2 in conversation