CALL SET Routine

Links SAS data set variables to DATA step or macro variables that have the same name and data type.

Category: Variable Control


CALL SET(data-set-id);

Required Argument


is the identifier that is assigned by the OPEN function when the data set is opened.


Using SET can significantly reduce the coding that is required for accessing variable values for modification or verification when you use functions to read or to manipulate a SAS file. After a CALL SET, whenever a read is performed from the SAS data set, the values of the corresponding macro or DATA step variables are set to the values of the matching SAS data set variables. If the variable lengths do not match, the values are truncated or padded according to need. If you do not use SET, then you must use the GETVARC and GETVARN functions to move values explicitly between data set variables and macro or DATA step variables.
As a general rule, use CALL SET immediately following OPEN if you want to link the data set and the macro and DATA step variables.

Example: Using the CALL SET Routine

This example uses the CALL SET routine:
  • The following statements automatically set the values of the macro variables PRICE and STYLE when an observation is fetched:
    %macro setvar;
       %let dsid=%sysfunc(open(sasuser.houses,i));
          /* No leading ampersand with %SYSCALL */ 
       %syscall set(dsid); 
       %let rc=%sysfunc(fetchobs(&dsid,10));
       %let rc=%sysfunc(close(&dsid));
    %mend setvar;
    %global price style;
    %put _global_;
  • The %PUT statement writes these lines to the SAS log:
    GLOBAL PRICE 127150
  • The following statements obtain the values for the first 10 observations in SASUSER.HOUSES and store them in MYDATA:
    data mydata;
          /* create variables for assignment */
          /*by CALL SET */
       length style $8 sqfeet bedrooms baths 8 
          street $16 price 8;
       drop rc dsid;
       call set (dsid);
       do i=1 to 10;