Requesting the addition of a [PRIVATE] keyword to protect user-defined package-scope PROC DS2 variables from direct access from outside an instance of the package.
Private variables and methods are a common feature of object orientated programming. See Why do we need private variables?.
Suppose this PROC DS2:
proc ds2 ;
	/* Create a piggy bank that applies business rules */
	package piggyBank / overwrite=YES;
		dcl double balance limit;
		method piggyBank();
			limit=1000;
			balance=0;
		end;
		method add_amount(double iAmount);
			if sum(iAmount, balance) > limit then
				put 'ERROR: Deposit exceedes limit!';
			else
				balance=sum(iAmount, balance);
		end;
		
		method print_balance();
			put balance=;
		end;
		
	endpackage;
	/* Create and add bogus amounts to the bank */
	data _null_;
		method run();
			dcl package piggyBank myBank();
			myBank.print_balance();
			
			/* No problem to add 45 to the balance */
			myBank.add_amount(45);
			
			/* This will print an error message */
			myBank.add_amount(5000);
			
			/* Bypass the business rules and directly set the balance.
				I propose a [PRIVATE] keyword that would prevent 
				`balance` from being directly accessible.
			*/
			myBank.balance=100000;
		end;
	enddata;
	run;
quit;
It is ashame that `piggyBank.balance` is directly accessible. You can bypass the business rules and directly edit the balance! My idea is for a `private` keyword that can be used to prevent direct access, something like:
package piggyBank / overwrite=YES; 
     dcl double [PRIVATE] balance; 
     /* ... code omitted for brevity ... */ 
     /* SAS won't compile this and will print an error */ 
     myBank.balance = 10000;
Apologies if there's a way that I'm missing to do this. Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.