SAS Interview Questions: Click Here
SAS Interview Questions: Click Here
SAS Interview Questions: Click Here
© Copyright by Interviewbit
Contents
19. Explain how %Let and macro parameters can be used to create micro variables
in SAS programming?
20. Name some SAS system options that are used to debug SAS Micros.
21. State the difference between PROC MEANS and PROC SUMMARY.
22. What do you mean by functions and procedures in SAS?
23. Identify the error in the following code.
24. Explain what you mean by SYMGET and SYMPUT.
25. What is the importance of the Tranwrd function in SAS.
26. How do you specify the number of iterations and specific conditions within a
single do loop?
27. Explain the usage of trailing @@.
28. Explain different ways to remove duplicate values in SAS.
29. What do you mean by NODUP and NODUPKEY options and write difference
between them?
30. Name the command used for sorting in SAS programs?
31. Explain what is INPUT and INFILE Statement.
32. What do you mean by %Include and %Eval?
SAS (Statistical Analytics System) is one of the leading analytics so ware tools and
has been developed by SAS Institute. It provides users with the ability to alter,
manage and retrieve different kinds of data from different sources, as well as perform
statistical analysis on collected data. SAS so ware lets you perform a number of
operations on data, including data management, statistical analysis, report writing,
business modelling, application development, quality improvement, data extraction,
and data transformation.
As shown above, SAS extracts raw data from different sources, cleans the data, and
stores or loads it in a database. SAS extracts and categorizes data in tables that help
you identify and analyze data patterns. Using this tool will allow you to increase
employee productivity and business profits through qualitative techniques and
procedures like advanced analytics, multivariate analysis, business intelligence,
handling data management functions, or predictive analytics. SAS is driven by SAS
programmers, who perform a series of operations on SAS datasets in order to
generate reliable statistical data reports for taking business decisions. Non-technical
users have access to a graphical interface with point-and-click functionality and more
advanced options with SAS language.
In this article, we will discuss concepts on SAS ranging from freshers to experienced
level, including reading and data manipulation, reporting, SAS macros, SQL queries,
SAS programming, etc.
Access Data: Data accessibility is a powerful SAS capability. In other words, data
can be accessed from different sources including raw databases, excel files,
Oracle databases, SAS datasets, etc.
Manage Data: SAS offers additional capabilities including data management.
Data accessed from a variety of sources can thus be managed easily in order to
generate useful insights. The process of managing data can include creating
variables, validating data, cleaning data, creating subsets, etc. SAS manages the
existing data to provide the data that you need.
Analyze Data: SAS will analyze the data once it has been managed to perform
simple evaluations like frequency and averages, along with more complex
evaluations like forecasting, regression, etc.
Present: The analyzed data can be saved and stored as a graphic report, a list,
and overall statistics that can be printed or published. They can also be saved
into a data file.
SAS, at the start of each iteration of the data step, reads the data statement and puts
the missing values of variables (assigned either through an INPUT statement or via an
assignment statement within the data step) into the program data vector (logical
areas of memory). RETAIN statements override this default. In other words, a RETAIN
statement instructs SAS not to set variables to missing when moving from one
iteration of the data step to another. The variables are instead retained.
Syntax:
RETAIN variable1 variable2 ... variablen;
There are no limits to the number of variables you can specify. When you do not
specify variable names, SAS retains the values of every variable that was created in
INPUT or assignment statement by default.
1
22
333
4444
55555
Following are the steps to create a SAS data set using these data. The numeric
informat 5 is used for this data step and the informatted length of the variable NUM is
matched by only one input record.
data readin;
infile 'external-file' missover;
input NUM 5.;
run;
proc print data=readin;
run;
Output:
Obs ID
1 .
2 .
3 .
4 .
5 55555
Those values that were read from input records that were too short have been set to
missing. This problem can be corrected by using the TRUNCOVER option in the INFILE
statement:
Truncover: This option assigns the raw data value to the variable, even if it is
shorter than what the INPUT statement expects.
Example:
An external file with variable-length records, for example, contains the following
records:
1
22
333
4444
55555
Following are the steps to create a SAS data set using these data. The numeric
informat 5 is used for this data step.
data readin;
infile 'external-file' truncover;
input NUM 5.;
run;
proc print data=readin;
run;
Output:
Obs ID
1 1
2 22
3 333
4 4444
5 55555
Those values that were read from input records that were too short are not set to
missing.
7. What do you mean by the Scan function in SAS and write its
usage?
The Scan() function is typically used to extract words from a value marked by
delimiters (characters or special signs that separate words in a text string). The SCAN
function selects individual words from text or variables containing text and stores
them in new variables.
Syntax:
scan(argument,n,delimiters)
In this case,
Argument: It specifies the character variable or text to be scanned.
N: The number n indicates which word to read.
Delimiters: These are characters values or special signs in a text string.
Example:
Consider that we would like to extract the first word from a sentence 'Hello, Welcome
to Scaler!'. In this case, the delimiter used is a blank.
data _null_;
string="Hello, Welcome to Scaler!";
first_word=scan(string, 1, ' ' );
put first_word =;
run;
First_word returns the word 'hello' since it's the first word in the above sentence.
Now, consider that we would like to extract the last word from a sentence 'Hello,
Welcome to Scaler!'. In this case, the delimiter used is a blank.
data _null_;
string="Hello, Welcome to Scaler!";
last_word=scan(string, -1, ' ' );
put last_word =;
run;
Last_word returns 'Scaler!' As Scaler is the last word in the above sentence.
In the above program, we have used the scan function to read the 3rd word in the
address string. The following output will the returned by the scan function:
x=Marg;
data sample;
do developerobs=1 to engineeringobs by 10;
set master.research point=developerobs nobs=engineeringobs;
output;
end;
stop;
run;
Example: Each line of input data can be used to create two or more observations. As
given below, for each observation in the data set Scaler, three observations are
created in the SAS data set Result.
data Result(drop=time4-time6);
set Scaler;
time=time4;
output;
time=time5;
output;
time=time6;
output;
run;
11. State the difference between using the drop = data set
option in the set statement and data statement.
In SAS, the drop= option is used to exclude variables from processing or from the
output data set. This option tells SAS which variables you wish to remove from a data
set.
The drop= option in the set statement can be used if you do not wish to process
certain variables or do not want to have them included in the new data set.
However, if you want to process certain variables but don't want them to be
included in the new data set, then choose drop= in the data statement.
Syntax: DROP=variable(s);
In this case, variable(s) lists one or more names of variables. Variables can be listed in
any format SAS supports.
Example: Consider the following data set:
DATA outdata;
INPUT gender $ section score1 score2;
DATALINES;
F A 17 20
F B 25 17
F C 12 15
M D 21 25
;
proc print;
run;
The following DROP= data set option command SAS to drop variables score1 and
score2.
data readin;
set outdata (drop = score1 score2);
totalsum = sum(score1, score2);
run;
Output:
13. What do you mean by the "+" operator and sum function?
In SAS, summation or addition is performed either with the “sum” function or by
using the “+” operator. Function "Sum" returns the sum of arguments that are
present (non-missing arguments), whereas "+" operator returns a missing value if
one or more arguments are not present or missing.
Example: Consider a data set containing three variables a, b, and c.
data variabledata;
input a b c;
cards;
1 2 3
34 3 4
. 3 2
53 . 3
54 4 .
45 4 2
;
run;
There are missing values for all variables and we wish to compute the sum of all
variables.
data sumofvariables;
set variabledata;
x=sum(a,b,c);
y=a+b+c;
run;
Output:
x y
6 6
41 41
5 .
56 .
58 .
51 51
The value of y is missing for the 3rd, 4th, and 5th observations in the output.
_N_: Typically, this variable is used to keep track of the number of times a data
step has been iterated. It is set to 1 by default. The variable _N_ increases every
time the data step of a data statement is iterated.
_ERROR_: The value is 0 by default and gives information about any errors that
occur during execution. Whenever there is an error, such as an input data error, a
math error, or a conversion error, the value is set to 1. This variable can be used
to locate errors in data records and to display an error message in the SAS log.
DATA outdata;
INPUT gender $ section score1 score2;
DATALINES;
F A 17 20
F B 25 17
F C 12 15
M D 21 25
;
proc print;
run;
The following DROP statement instructs SAS to drop variables score1 and score2.
data readin;
set outdata;
totalsum = sum(score1,score2);
drop score1, score2;
run;
Output:
The following KEEP statement instructs SAS to retain score1 in the data set.
data readin1;
set readin;
keep score1;
run;
Output:
16. What are some common mistakes that people make while
writing programs in SAS?
The following are some of the most common programming errors in SAS:
If a semicolon is missing from a statement, SAS will misinterpret not only that
statement but potentially several that follow.
A number of errors will result from unclosed quotes and unclosed comments
because SAS may fail to read the subsequent statements correctly.
Data and procedure steps have very different functions in SAS, so statements
that are valid in one will probably cause errors in the other.
Data is not sorted before using a statement that requires a sort
Submitted programs are not checked for log entries.
The quotation marks are not matched.
The dataset option is invalid or the statement option is invalid.
Debugging techniques are not used.
In the following program, we have created the Macro variable in which we pass the
parameters comma-separated and then we have written the Macro statement
followed by the %MEND statement. A er that, we have called the macro program by
passing the parameters.
Any number, text or date can be entered in the Value field, depending on what the
program requires.
How to use the Micro Variable?
Whenever referencing macro variables, an ampersand (&) is used followed by the
macro variable name as shown below:
& <Macro variable Name>
Macro Parameters: Macros have variables called parameters whose values you set
when you invoke the macro. The parameters are added to a macro by naming them
in parenthesis in %macro.
Syntax:
20. Name some SAS system options that are used to debug SAS
Micros.
There are a number of SAS System options that users can use to troubleshoot macro
problems and issues. Macro-option results are automatically shown in the SAS Log.
MEMRPT: Displays memory usage statistics in the SAS logs.
MERROR: SAS will issue a warning if we attempt to invoke a macro that SAS
does not recognize. Whenever there is a misspelling or if a macro is not defined,
warning messages are displayed.
MLOGIC: SAS prints details about the macro execution in its log. In short, it
identifies and displays micro logic.
MPRINT: When you execute a macro code, SAS doesn't show it in the LOG file,
but when you use the MPRINT option it displays all the SAS statements of the
resolved macro code. With the MPRINT option, one statement per line is printed
along with the corrected macro code.
SYMBOLGEN: It prints a message in the LOG file about how a macro variable is
resolved. Specifically, a message is printed in the LOG whenever a macro variable
is resolved.
SCAN()
NPUT()
SUBSTR()
COUNTC()
COMPRESS(), etc.
Basically, it is a syntax error. In all cases, the MODEL statement must appear a er the
CLASS statement.
Syntax of SYMGET:
SYMGET(argument)
Example: In the following program we have created a macro variable and then we
have used the symput function to put the value where our key is 'avar' and then we
have used the symget function to get the micro variable value.
Here,
The source is a character constant, variable, or expression you wish to translate.
The target is an expression, constant, or variable searched in the source.
Replacement specifies an expression, constant, or variable that will replace
target.
Example:
name : Mrs. Johny Lever
name=tranwrd(name, "Mrs.", "Ms.");
Result : Ms. Johny Lever
The code below illustrates how to specify the number of iterations and specific
conditions within a single do loop. The iterative DO statement executes the DO loop
until the Sum is greater than or equal to 50000, or until the DO loop has executed 10
times, whichever comes first.
data Scaler;
do i=1 to 50 until (Sum>=50000);
Year+1;
Sum+5000;
Sum+Sum*.10;
end;
run;
proc sql;
create table New_dataset as select distinct * from Old_dataset where var=distinct(var);
quit;
NODUP NODUPKEY
Syntax: Syntax:
PROC SORT DATA=readin NODUP; PROC SORT DATA=readin NODUPKEY;
By varname; By varname;
run; run;
Here,
Example:
DATA readin
INFILE Test;
INPUT ID Gender Score;
Run;
%INCLUDE source(s)
</<SOURCE2> <S2=length> <option-list> >;
Here,
Source(s) specify the location of the information that you wish to access with
the %INCLUDE statement.
SOURCE2 causes the SAS log to show the source statements being used in your
SAS program.
S2=length specifies the length of the input record.
Option-list specifies options that can be included in %INCLUDE.
Example:
%let d=%eval(13+23);
Conclusion
Have you been preparing for a SAS interview and wondering how you can succeed?
This useful guide can help you prepare for it. We've compiled a list of the top 30+ SAS
interview questions and answers that you're likely to be asked during your interviews.
The questions have been specifically designed to familiarize you with the type of
questions you might encounter during the interview.
Css Interview Questions Laravel Interview Questions Asp Net Interview Questions