I've become interested in the PROC DS2 package functionality and have been trying to learn as much as I can.
I'm reading this paper right now for reference: https://support.sas.com/resources/papers/proceedings16/7280-2016.pdf
In the paper, the author talks about how SAS automatically includes getter and setter methods in packages that can be called by adding the prefix "get_" or "set_". My question, is there any documentation on the methods that are automatically included in packages?
Additionally, in the paper (bottom of page 6, top of page 7) they create a teacher package which "inherits" from the person package. At one point they reference "get_pname" to get the name from the person package and I was wondering if "get_p" is a predefined prefix? or is there something I'm missing?
Thanks!
I may be wrong but it seems that in the doc. this is the only place where "get_" pops-up:
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/ds2pg/n0uuczirxf453en14a69dnwl3kyp.htm
in
next = cur.get_next();
but it does not mention anything about getters or setters.
But the article is 100% accurate, this code (extended version of the paper one):
data class;
set sashelp.class;
run;
Proc ds2;
package counter / overwrite=yes;
dcl int Bvalue;
method counter();
Bvalue=0;
end;
method add();
Bvalue=Bvalue+1;
end;
endpackage;
package gluerer / overwrite=yes;
dcl varchar(1024) Gvalue;
method counter();
Gvalue='';
end;
method add();
Gvalue=Strip(Gvalue)!!'+';
end;
endpackage;
run;
data _null_;
dcl package counter boycounter();
dcl package gluerer girlcounter();
dcl int nummales;
dcl varchar(1024) charfemales;
method init();
boycounter.set_Bvalue(100);
girlcounter.set_Gvalue('***');
end;
method run();
set class;
put sex=;
if sex='M' then boycounter.add();
else girlcounter.add();
end;
method term();
nummales=boycounter.get_Bvalue();
charfemales=girlcounter.get_Gvalue();
put nummales= charfemales=;
end;
enddata;
run;
quit;
gives the following log:
1 data class;
2 set sashelp.class;
3 run;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLASS has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.00 seconds
4
5 Proc ds2;
NOTE: Writing HTML Body file: sashtml.htm
6 package counter / overwrite=yes;
7 dcl int Bvalue;
8
9 method counter();
10 Bvalue=0;
11 end;
12
13 method add();
14 Bvalue=Bvalue+1;
15 end;
16
17 endpackage;
18
19 package gluerer / overwrite=yes;
20 dcl varchar(1024) Gvalue;
21
22 method counter();
23 Gvalue='';
24 end;
25
26 method add();
27 Gvalue=Strip(Gvalue)!!'+';
28 end;
29
30 endpackage;
31 run;
NOTE: Created package counter in data set work.counter.
NOTE: Created package gluerer in data set work.gluerer.
NOTE: Execution succeeded. No rows affected.
32
33
34 data _null_;
35 dcl package counter boycounter();
36 dcl package gluerer girlcounter();
37 dcl int nummales;
38 dcl varchar(1024) charfemales;
39
40 method init();
41 boycounter.set_Bvalue(100);
42 girlcounter.set_Gvalue('***');
43 end;
44
45
46 method run();
47 set class;
48 put sex=;
49 if sex='M' then boycounter.add();
50 else girlcounter.add();
51 end;
52
53 method term();
54 nummales=boycounter.get_Bvalue();
55 charfemales=girlcounter.get_Gvalue();
56 put nummales= charfemales=;
57 end;
58 enddata;
59 run;
Sex=M
Sex=F
Sex=F
Sex=F
Sex=M
Sex=M
Sex=F
Sex=F
Sex=M
Sex=M
Sex=F
Sex=F
Sex=F
Sex=F
Sex=M
Sex=M
Sex=M
Sex=M
Sex=M
nummales=110 charfemales=***+++++++++
NOTE: Execution succeeded. No rows affected.
60 quit;
NOTE: PROCEDURE DS2 used (Total process time):
real time 0.16 seconds
cpu time 0.14 seconds
Bart
I may be wrong but it seems that in the doc. this is the only place where "get_" pops-up:
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/ds2pg/n0uuczirxf453en14a69dnwl3kyp.htm
in
next = cur.get_next();
but it does not mention anything about getters or setters.
But the article is 100% accurate, this code (extended version of the paper one):
data class;
set sashelp.class;
run;
Proc ds2;
package counter / overwrite=yes;
dcl int Bvalue;
method counter();
Bvalue=0;
end;
method add();
Bvalue=Bvalue+1;
end;
endpackage;
package gluerer / overwrite=yes;
dcl varchar(1024) Gvalue;
method counter();
Gvalue='';
end;
method add();
Gvalue=Strip(Gvalue)!!'+';
end;
endpackage;
run;
data _null_;
dcl package counter boycounter();
dcl package gluerer girlcounter();
dcl int nummales;
dcl varchar(1024) charfemales;
method init();
boycounter.set_Bvalue(100);
girlcounter.set_Gvalue('***');
end;
method run();
set class;
put sex=;
if sex='M' then boycounter.add();
else girlcounter.add();
end;
method term();
nummales=boycounter.get_Bvalue();
charfemales=girlcounter.get_Gvalue();
put nummales= charfemales=;
end;
enddata;
run;
quit;
gives the following log:
1 data class;
2 set sashelp.class;
3 run;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLASS has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.00 seconds
4
5 Proc ds2;
NOTE: Writing HTML Body file: sashtml.htm
6 package counter / overwrite=yes;
7 dcl int Bvalue;
8
9 method counter();
10 Bvalue=0;
11 end;
12
13 method add();
14 Bvalue=Bvalue+1;
15 end;
16
17 endpackage;
18
19 package gluerer / overwrite=yes;
20 dcl varchar(1024) Gvalue;
21
22 method counter();
23 Gvalue='';
24 end;
25
26 method add();
27 Gvalue=Strip(Gvalue)!!'+';
28 end;
29
30 endpackage;
31 run;
NOTE: Created package counter in data set work.counter.
NOTE: Created package gluerer in data set work.gluerer.
NOTE: Execution succeeded. No rows affected.
32
33
34 data _null_;
35 dcl package counter boycounter();
36 dcl package gluerer girlcounter();
37 dcl int nummales;
38 dcl varchar(1024) charfemales;
39
40 method init();
41 boycounter.set_Bvalue(100);
42 girlcounter.set_Gvalue('***');
43 end;
44
45
46 method run();
47 set class;
48 put sex=;
49 if sex='M' then boycounter.add();
50 else girlcounter.add();
51 end;
52
53 method term();
54 nummales=boycounter.get_Bvalue();
55 charfemales=girlcounter.get_Gvalue();
56 put nummales= charfemales=;
57 end;
58 enddata;
59 run;
Sex=M
Sex=F
Sex=F
Sex=F
Sex=M
Sex=M
Sex=F
Sex=F
Sex=M
Sex=M
Sex=F
Sex=F
Sex=F
Sex=F
Sex=M
Sex=M
Sex=M
Sex=M
Sex=M
nummales=110 charfemales=***+++++++++
NOTE: Execution succeeded. No rows affected.
60 quit;
NOTE: PROCEDURE DS2 used (Total process time):
real time 0.16 seconds
cpu time 0.14 seconds
Bart
Appreciate both the replies. Unfortunate that the feature isn't really documented since having automatic generation of getters and setters would seem to be useful functionality.
Concerning my other question about the "get_pname()" statement. I had been wondering if the "get_p" prefix was an auto generated parent getter but, I just ran through the code, it seems like it's just a typo and should have been "get_name()".
Thank you again for the help.
Mark, maybe you will be able to help here?
Bart
@yabwon I've used this type of code before in DS2 programs but have never seen it documented. I'll attempt to find out why...
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.