The interview is one of the crucial stage if you are a student and planning to get into the field of SAS Professional. One would definitely have a situation in favor a bit if he or she hold SAS certification, however, to want to leverage the certification credentials, one should do well in the Interview as well. Our experts from the industry have collected some questions of SAS Base Programmer which can be useful in your SAS certification exam and more importantly in the interview. This set of interview questions can help an SAS student in getting into the dream profession.
Collection of Questions
1. What is the function of output statement?
Ans:
To override the default way in which the DATA step writes observations to output, you can use an OUTPUT statement in the DATA step. Placing an explicit OUTPUT statement in a DATA step overrides the automatic output, so that observations are added to a data set only when the explicit OUTPUT statement is executed.
2. What is the function of Stop statement?
Ans:
Stop statement causes SAS to stop processing the current data step immediately and resume processing statement after the end of current data step.
3. What is the difference between using drop= data set option in data statement and set statement?
Ans:
If you don’t want to process certain variables and you do not want them to appear in the new data set, then specify drop= data set option in the set statement.
Whereas If want to process certain variables and do not want them to appear in the new data set, then specify drop= data set option in the data statement.
4. Given an unsorted dataset, how to read the last observation to a new data set?
Ans:
Using end= data set option.
For example:
data work.calculus;
set work.comp end=last;
If last;
run;
Where Calculus is a new data set to be created and Comp is the existing data set
Last is the temporary variable (initialized to 0) which is set to 1 when the set statement reads the last observation.
5. What is the difference between reading the data from external file and reading the data from existing data set?
Ans:
The main difference is that while reading an existing data set with the SET statement, SAS retains the values of the variables from one observation to the next.
6. What is the difference between SAS function and procedures?
Ans:
Functions expects argument value to be supplied across an observation in a SAS data set and procedure expects one variable value per observation.
For example:
data average ;
set temp ;
avgtemp = mean( of T1 – T24 ) ;
run ;
Here arguments of mean function are taken across an observation.
proc sort ;
by month ;
run ;
proc means ;
by month ;
var avgtemp ;
run ;
Proc means is used to calculate average temperature by month (taking one variable value across an observation).
7. Difference b/w sum function and using “+” operator?
Ans:
SUM function returns the sum of non-missing arguments whereas “+” operator returns a missing value if any of the arguments are missing.
Example:
data mydata;
input x y z;
cards;
33 3 3
24 3 4
24 3 4
. 3 2
23 . 3
54 4 .
35 4 2
;
run;
data mydata2;
set mydata;
a=sum(x,y,z);
p=x+y+z;
run;
In the output, value of p is missing for 3rd, 4th and 5th observation as :
a p
39 39
31 31
31 31
5 .
26 .
58 .
41 41
8. What would be the result if all the arguments in SUM function are missing?
Ans:
A missing value
9. What would be the denominator value used by the mean function if two out of seven arguments are missing?
Ans:
Five
10. Give an example where SAS fails to convert character value to numeric value automatically?
Ans:
Suppose value of a variable PayRate begins with a dollar sign ($). When SAS tries to automatically convert the values of PayRate to numeric values, the dollar sign blocks the process. The values cannot be converted to numeric values.
Therefore, it is always best to include INPUT and PUT functions in your programs when conversions occur.
11. What would be the resulting numeric value (generated by automatic char to numeric conversion) of a below mentioned character value when used in arithmetic calculation?
1,735.00
Ans:
A missing value
12. What would be the resulting numeric value (generated by automatic char to numeric conversion) of a below mentioned character value when used in arithmetic calculation?
1735.00
Ans:
1735
13. Which SAS statement does not perform automatic conversions in comparisons?
Ans:
where statement
14. Briefly explain Input and Put function?
Input function – Character to numeric conversion- Input(source,informat)
put function – Numeric to character conversion- put(source,format)
15. What would be the result of following SAS function (given that 31 Dec, 2000 is Sunday)?
Weeks = intck (‘week’,’31 dec 2000′d,’01jan2001′d);
Years = intck (‘year’,’31 dec 2000′d,’01jan2001′d);
Months = intck (‘month’,’31 dec 2000′d,’01jan2001′d);
Ans:
Weeks=0, Years=1, Months=1
16. What are the parameters of Scan function?
Ans:
Scan(argument,n,delimiters)
argument specifies the character variable or expression to scan
n specifies which word to read
delimiters are special characters that must be enclosed in single quotation marks
17. Suppose the variable address stores the following expression: 209 RADCLIFFE ROAD, CENTER CITY, NY, 92716. What would be the result returned by the scan function in the following cases?
a=scan(address,3);
b=scan(address,3,’,');
Ans:
a=Road; b=NY
18. What is the length assigned to the target variable by the scan function?
Ans:
200
19. Name few SAS functions?
Ans:
Scan, Substr, trim, Catx, Index, tranwrd, find, Sum.
20. What is the function of tranwrd function?
Ans:
TRANWRD function replaces or removes all occurrences of a pattern of characters within a
character string.
21. Consider the following SAS Program
data finance.earnings;
Amount=1000;
Rate=.075/12;
do month=1 to 12;
Earned+(amount+earned)*(rate);
end;
run;
What would be the value of month at the end of data step execution and how many observations would be there?
Ans:
Value of month would be 13
No. of observations would be 1
22. Consider the following SAS Program
data finance;
Amount=1000;
Rate=.075/12;
do month=1 to 12;
Earned+(amount+earned)*(rate);
output;
end;
run;
23. How many observations would be there at the end of data step execution?
Ans:
12
24. How do you use the do loop if you don’t know how many times should you execute the do loop?
Ans:
we can use do until or do while to specify the condition.
25. What the difference is between do while and do until?
Ans:
An important difference between the DO UNTIL and DO WHILE statements is that the DO WHILE expression is evaluated at the top of the DO loop. If the expression is false the first time it is evaluated, then the DO loop never executes. Whereas DO UNTIL executes at least once.
26: How do you specify number of iterations and specific condition within a single do loop?
Ans:
data work;
do i=1 to 20 until(Sum>=20000);
Year+1;
Sum+2000;
Sum+Sum*.10;
end;
run;
This iterative DO statement enables you to execute the DO loop until Sum is greater than or equal to 20000 or until the DO loop executes 10 times, whichever occurs first.
27: How many data types are there in SAS?
Ans:
Character, Numeric
28: If a variable contains only numbers, can it be character data type? Also give example
Ans:
Yes, it depends on how you use the variable
Example: ID, Zip are numeric digits and can be character data type.
29: If a variable contains letters or special characters, can it be numeric data type?
Ans:
No, it must be character data type.
29: What can be the size of largest dataset in SAS?
Ans:
The number of observations is limited only by computer’s capacity to handle and store them.
Prior to SAS 9.1, SAS data sets could contain up to 32,767 variables. In SAS 9.1, the maximum number of variables in a SAS data set is limited by the resources available on your computer.
30: Give some example where PROC REPORT’s defaults are different than PROC PRINT’s defaults?
Ans:
No Record Numbers in Proc Report
Labels (not var names) used as headers in Proc Report
REPORT needs NOWINDOWS option
31: Give some example where PROC REPORT’s defaults are same as PROC PRINT’s defaults?
Ans:
Variables/Columns in position order.
Rows ordered as they appear in data set.
32: Highlight the major difference between below two programs:
Program 1:
data mydat;
input ID Age;
cards;
2 23
4 45
3 56
9 43
;
run;
proc report data = mydat nowd;
column ID Age;
run;
Program 2:
data mydat1;
input grade $ ID Age;
cards;
A 2 23
B 4 45
C 3 56
D 9 43
;
run;
proc report data = mydat1 nowd;
column Grade ID Age;
run;
Ans:
When all the variables in the input file are numeric, PROC REPORT does a sum as a default.Thus first program generates one record in the list report whereas second generates four records.
33: In the above program, how will you avoid having the sum of numeric variables?
Ans:
To avoid having the sum of numeric variables, one or more of the input variables must be defined as DISPLAY.
Thus we have to use:
proc report data = mydat nowd;
column ID Age;
define ID/display;
run;
34: What is the difference between Order and Group variable in proc report?
Ans:
If the variable is used as group variable, rows that have the same values are collapsed.
Group variables produce list report whereas order variable produces summary report.
35: Give some ways by which you can define the variables to produce the summary report (using proc report)?
Ans:
All of the variables in a summary report must be defined as group, analysis, across, or Computed variables.
36: What are the default statistics for means procedure?
Answer: n-count, mean, standard deviation, minimum, and maximum
37: How to limit decimal places for variable using PROC MEANS?
Ans:
By using MAXDEC= option
38: What is the difference between CLASS statement and BY statement in proc means?
Ans:
Unlike CLASS processing, BY processing requires that your data already be sorted or indexed in the order of the BY variables.
BY group results have a layout that is different from the layout of CLASS group results
39: What is the difference between PROC MEANS and PROC Summary?
Ans:
The difference between the two procedures is that PROC MEANS produces a report by default. By contrast, to produce a report in PROC SUMMARY, you must include a PRINT option in the PROC SUMMARY statement.
40: How to specify variables to be processed by the FREQ procedure?
Ans:
By using TABLES Statement.
41: Describe CROSSLIST option in TABLES statement?
Ans:
Adding the CROSSLIST option to TABLES statement displays crosstabulation tables in ODS column format.
42: How to create list output for crosstabulations in proc freq?
Ans:
To generate list output for crosstabulations, add a slash (/) and the LIST option to the TABLES statement in your PROC FREQ step.
TABLES variable-1*variable-2 <* … variable-n> / LIST;
43: Proc Means work for ________ variable and Proc FREQ Work for ______ variable?
Ans:
Numeric, Categorical
44: How can you combine two datasets based on the relative position of rows in each data set; that is, the first observation in one data set is joined with the first observation in the other, and so on?
Ans:
One to One reading
45: What would be the format of Revenue in resulting dataset (concat) for following?
data concat;
set a b;
run;
Format of variable Revenue in dataset a is dollar10.2 and format of variable Revenue in dataset b is dollar12.2
Ans:
dollar10.2
46: If you have two datasets you want to combine them in the manner such that observations in each BY group in each data set in the SET statement are read sequentially, in the order in which the data sets and BY variables are listed then which method of combining datasets will work for this?
Ans:
Interleaving
47: While match merging two data sets, you cannot use the __________option with indexed data sets because indexes are always stored in ascending order.
Ans:
Descending
48: What is the difference between One to One Merge and Match Merge? Give example also.
Ans:
If both data sets in the merge statement are sorted by id(as shown below) and each observation in one data set has a corresponding observation in the other data set, a one-to-one merge is suitable.
data mydata1;
input id class $;
cards;
1 Sa
2 Sd
3 Rd
4 Uj
;
data mydata2;
input id class1 $;
cards;
1 Sac
2 Sdf
3 Rdd
4 Lks
;
data mymerge;
merge mydata1 mydata2;
run;
If the observations do not match, then match merging is suitable
data mydata1;
input id class $;
cards;
1 Sa
2 Sd
2 Sp
3 Rd
4 Uj
;
data mydata2;
input id class1 $;
cards;
1 Sac
2 Sdf
3 Rdd
3 Lks
5 Ujf
;
data mymerge;
merge mydata1 mydata2;
by id
run;