Announcement

Collapse
No announcement yet.

Using a Macro Library with Screen Code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using a Macro Library with Screen Code

    Using a Macro Library with Screen Code

    As with Base SAS, a macro library can also be used within the SAS SCL language. This provides a simple way to create a code library for common edit checks that are used within the Data Entry Screen Design.

    Basically, macros work in the same way as within Base SAS. You create a SAS program named the same as the macro defined within and place this in a macro library. Then in your code, you call the macro by using %macroname;

    The only difference is that this program contains SAS SCL code inside the macro definition instead of Base SAS code. However, one thing to keep in mind is that with SCL, the macro is resolved when the Data Entry Screen is compiled, not when it is used. Therefore, to update a change made to a macro, all the screens using this code must be recompiled.

    Example
    Say we want to check that all Patient Initial fields do not contain a number, we could write the following macro code and save it in either a Global, Source or Study level macro library;

    Macro CHECKINIT.SAS
    Code:
    /*****************************************\
    Macro to check initials do not contain 
    a number.
    
    Programmer: 	GWagner
    Date:				01/25/2005
    \*****************************************/
    %macro checkinit;
    	if _self_.text > '' then do;
    		if length(_self_.text) ^=length(compress(_self_.text,'1234567890')) then do;
    			_self_._errorOn();
    			_self_.cpErrorMessage='Initials can not contain numbers';
    			return;
    		end;
    	end;
    %mend checkinit;
    onLostFocus
    And then within our onLostFocus code, add the macro. the onLostFocus code would look like this - the call is bolded;
    Code:
    /** OnLostFocus Method **/
    
    %include objfile;
    
    _OnLostFocus: method _self_:u:object;
    link createobj;
    ************************;
    ** Add user code here **;
    ************************;
    
    %checkinit;
    
    
    endmethod;
    Last edited by Ronni Rubenstein; 01-05-2007, 01:36 PM.
Working...
X