EZ Study

Actuarial Biology Chemistry Economics Calculators Confucius Engineer

SAS Interview Frequently Asked Macro Questions -4

27. What are SYMGET and SYMPUT?
SYMPUT puts the value from a dataset into a macro variable where as SYMGET gets the value from the macro variable to the dataset.

28. What are the macros you have used in your programs?
Used macros for various puposes, few of them are..

1) Macros written to determine the list of variables in a dataset:
%macro varlist (dsn);
proc contents data = &dsn out = cont noprint; run;

proc sql noprint;
select distinct name into:varname1-:varname22 from cont; quit;

%do i =1 %to &sqlobs;
%put &i &&varname&i;
%mend varlist;

2) Distribution or Missing / Non-Missing Values
%macro missrep (dsn, vars=_numeric_);
proc freq data=&dsn.;
tables &vars. / missing;
format _character_ $missf. _numeric_ missf.;
title1 'Distribution or Missing / Non-Missing Values'; run;
%mend missrep;
%missrep(study.demog, vars=age gender bdate);

3) Written macros for sorting common variables in various datasets
%macro sortit (datasetname,pid,inverstigator);
%mend sortit;
%sortit (ae,001,sarath);

4) Macros written to split the number of observations in a dataset

%macro split (dsnorig, dsnsplit1, dsnsplit2, obs1);
data &dsnsplit1;
set &dsnorig (obs = &obs1); run;
data &dsnsplit2;
set &dsnorig (firstobs = %eval(&obs1 + 1)); run;

%mend split;

29. What is auto call macro and how to create a auto call macro? What is the use of it? How to use it in SAS with macros?
SAS Enables the user to call macros that have been stored as SAS programs.

The auto call macro facility allows users to access the same macro code from multiple SAS programs. Rather than having the same macro code for in each program where the code is required, with an autocall macro, the code is in one location. This permits faster updates and better consistency across all the programs.Macro set-up:The fist step is to set-up a program that contains a macro, desired to be used in multiple programs. Although the program may contain other macros and/or open code, it is advised to include only one macro.

Before one can use the autocall macro within a SAS program, The MAUTOSOURSE option must be set open and the SASAUTOS option should be assigned. The MAUTOSOURSE option indicates to SAS that the autocall facility is to be activated. The SASAUTOS option tells SAS where to look for the macros.

For ex: sasauto='g:\busmeas\internal\macro\';

30. Why and How to Use %PUT Statement:
%Put statement is similar to the PUT statement in data step, What it does is it writes text and values of macro variable after execution to the SAS System LOG. If you want to make sure your macro variable resolves as expected, you can make sure it with %PUT statement.

Unique advantage of %PUT over PUT is you can use %PUT outside the data step whereas you can't with PUT.

How to use %PUT:
%let program=AE;
%put program Name here as &program;
Above %put statement resolves to %put Program Name here as AE;
What can you do with %PUT:
Numerous options are available for the %PUT statement.
%PUT _all_: It prints all macro variables in the log that are available in all environments (global, local, user and automatic).

%PUT _automatic_: It prints all the SAS defined automatic macro variables in the log. (ex: &sysdate, &systime ,%sysdsn, %syserr etc)

%PUT _global_: It prints macro variables that are created by the user and available in all environments.

%PUT _local_: It prints macro variables that are created by the user and available only in the local environment. (couldn't be able use those macro variables outside the particular data step)

%PUT _user_: prints macro variables that created by the user in each environment.

Related links:

Continue Top 25 SAS Interview Questions   SAS Tutorial
SAS Interview Frequently Asked Macro Questions -3   SAS Interview