1.02 is Greater Than Zero
. is Missing
-.38 is Less Than Zero
Example 3: Translating Characters
%SYSFUNC executes the TRANSLATE function to translate the Ns in a string to Ps.
%let string1 = V01N01-V01N10;
%let string1 = %sysfunc(translate(&string1,P, N));
%put With N translated to P, V01N01-V01N10 is &string1;
When these statements are executed, these lines are written to the SAS log:
With N translated to P, V01N01-V01N10 is V01P01-V01P10
Example 4: Confirming the Existence of a SAS Data Set
The macro CHECKDS uses %SYSFUNC to execute the EXIST function, which checks
the existence of a data set:
%macro checkds(dsn);
%if %sysfunc(exist(&dsn)) %then
%do;
proc print data=&dsn;
run;
%end;
%else
%put The data set &dsn does not exist.;
%mend checkds;
%checkds(Sasuser.Houses)
When the program is executed, the following statements will be produced:
PROC PRINT DATA=SASUSER.HOUSES;
RUN;
Example 5: Determining the Number of Variables and Observations
in a Data Set
Many solutions have been generated in the past to obtain the number of variables and
observations present in a SAS data set. Most past solutions have used a combination of
_NULL_ DATA steps, SET statement with NOBS=, and arrays to obtain this
information. Now, you can use the OPEN and ATTRN functions to obtain this
information quickly and without interfering with step boundary conditions.
%macro obsnvars(ds);
%global dset nvars nobs;
%let dset=&ds;
%let dsid = %sysfunc(open(&dset));
%if &dsid %then
%do;
%let nobs =%sysfunc(attrn(&dsid,NOBS));
%let nvars=%sysfunc(attrn(&dsid,NVARS));
%let rc = %sysfunc(close(&dsid));
%put &dset has &nvars variable(s) and &nobs observation(s).;
%end;
%else
%put Open for data set &dset failed - %sysfunc(sysmsg());
%mend obsnvars;
286 Chapter 17 • Macro Functions