BookmarkSubscribeRSS Feed
🔒 This topic is locked. We are no longer accepting replies to this topic. Need further help? Please sign in and ask a new question.
odesh
Quartz | Level 8

Hello,

 

I am not sure that I understand fully how the following work together:

- method

- package

- thread

- data statement.

 

Please tell me where I am right and where I am wrong.

 

Please refer to the attached ds2 program.

 

1. There seems to be a strict sequence in which these are constructed/defined,  declared/instantiated  and finally executed. 

method -> package -> thread -> data;  Can there be situations where this sequence is different ?

 

2. The method ourGMP and the package work.pkg_05s08 are set up ( defined) in the first few lines of the attached program. The method is contained in the package.

 

3. In the second part of the program, the thread work.th_05s08 is defined using the "thread ..endthread"  block syntax. Within this thread, the method and package defined above are declared/instantiated  ( Is there a difference between declare and instantiate ? )

and then executed together in the statement :

GrossMargin = myPkg.ourGMP(GrossSales, CostofGoods);

 

4. In the final part of the program, the thread is executed in a data step. I am not sure why "data;" is used here and not "data _null_ " or even "data <datasetname> . I guess the <datasetname> option would be used if we were outputting a dataset name. Is this correct ?

 

Thanks.

Odesh.

 

3 REPLIES 3
SASJedi
Ammonite | Level 13

1. Methods are named executable blocks of DS2 code. Methods are executed by DATA and THREAD programs. You can either define the method right in the DATA or THREAD program, or you can store several methods in a PACKAGE. The Package can then be instantiated in the DATA or DTREAD program, and the METHOD code accessed from the package as an alternative to re-writing the METHOD code for each THREAD or DATA program that requires the method.  

 

2. As you stated, the method ourGMP definition (code) is stored in the package work.pkg_05s08. So now the method is contained in the package.

 

3. The thread work.th_05s08 is defined using the "thread ..endthread"  block syntax. Within this thread, package work.pkg_05s08 is instantiated as myPkg, giving the THREAD program access to the methods stored in the package.  The assignment statement GrossMargin = myPkg.ourGMP(GrossSales, CostofGoods);  accesses the ourGMP method from myPkg to perform the calculation. (Yes, there a difference between declaration and instantiation of a package - see the material related to the SQLSTMT package later in this chapter - that section explains the difference.) 

 

4. Finally, the THREAD program is executed in parallel from a DATA program. A DATA program that does not specify a desitnation for the result set (data;) will produce a report instead of an output data set. 

 

Hope this helps!

Mark

 

Check out my Jedi SAS Tricks for SAS Users
odesh
Quartz | Level 8
Thanks Mark. Three follow-up questions:

1. Can I think of a rough "hierarchy" (top to bottom) comprising:
Data
Thread
Package
Method
Function .

2. But then the function SQLEXEC can be used to run a FedSQL query. Would
this fact contradict the "hierarchy" above ?

3. Are packages always contained in threads or can we build a thread within
a package ?

Thanks again.
Odesh.


SASJedi
Ammonite | Level 13

Odesh,

I like the hierarchy idea you laid out in question #1. To view the DS2 ecosystem in this vein, just add the rule that lower-level items in the hierarchy may be used as components in higher level items, but not vice-versa. So, for example, a method may include a function, and method may subsequently become part of a package, thread or data program. But a method cannot contain a package, thread or data program. I think this paradigm also speaks to question #3 - while a packages may be declared (used) in a thread or data program, the package cannot incorporate a thread or data program within the package.

As for question #2, I see no conflict with the hierarchy model described. A function is just a means of executing a particular task, and SQLEXEC fits well within the definition. According to the hierarchy, SQLEXEC could be used in a method, package, thread or data program - and this is true. 

Regards,

Mark

 

Check out my Jedi SAS Tricks for SAS Users