# 31 Tricky SAS Interview Questions for Freshers & Experience

## 1. Tricky SAS Interview Questions

In our last discussion **SAS Interview Questions, **we learned all generally asked SAS interview questions. Here in ’31 Tricky SAS Interview Questions’ we will learn the tricky questions which are frequently asked in SAS Interview. This Tricky SAS Interview Questions, involve many practical questions which will help you to prepare for SAS interview.

But first of all, let’s revise **SAS Programming** **Language**.** **

## 2. Mostly Asked Questions in SAS Interview

Following are the 30 Best Tricky SAS Interview Questions with Answers for Freshers & Experienced.

**Q1. What is the one statement to set the criteria of data that can be coded in any step?**

WHERE statement can sets the criteria for any data set in a data step or a proc step.

**Q2. How would you include common or reuse code to be processed along with your statements?**

– Using **SAS Macros**.

– Using a %include statement

** **

**Q3. When looking for data contained in a character string of 150 bytes, which function is the best to locate that data: scan, index, or indexc?**

**Index function** – Searches a character expression for a **string of characters **

SAS Statements |
Results |

a=’ABC.DEF (X=Y)’; b=’X=Y’; x=index(a,b); put x; |
10 |

**Q4. ****If you have a dataset that contains 100 variables, but you need only five of those, what is the code to force SAS to use only those variables?**

Use KEEP= dataset option (data statement or set statement) or KEEP statement in a datastep.

eg.

Data fewdata (keep = var10 var11); Set fulldata (Keep= VAR1 VAR2 VAR3 VAR4 VAR5); Keep var6 var7; Run;

**Read More about SAS Variables in detail**

**Q5**. **Code a PROC SORT on a data set containing State, District and County as the primary variables, along with several numeric variables.**

Proc sort data= Dist_County; By state district city; Run;

**Read about PROC SORT in detail**

**Q6. How would you code a merge that will keep only the observations that have matches from both sets?**

data mergeddata; merge one(in=A) two(in=B); By ID; if A and B; run;

** ****Q7. How would you code a merge that will write the matches of both to one data set, the non-matches from the left-most data.**

Data one two three; Merge DSN1 (in=A) DSN2 (in=B); By ID; If A and B then output one; If A and not B then output two; If not A and B then output three; Run;

**Read More About How to Merge DataSets in SAS Programming Language**

**Q8. Name statements that are recognized at compile time only?**

drop, keep, rename, label, format, informat, attrib, where, by, retain, length, array.

**Q9. What are the statements that are executed only?**

INFILE, INPUT, Output, Call routines

**Q10.Which are the statements whose placement in the DATA step is critical.**

DATA, INPUT, RUN, CARDS ,INFILE,WHERE,LABEL,SELECT,INFORMAT,FORMAT

**Q11. Name statements that function at both compile and execution time.**

Options, title, footnote

**Tricky SAS Interview Questions For Freshers. Q- 1,2,4,8,9,10,11**

**Tricky SAS Interview Questions For Experienced. Q- 3,5,6,7**

**Q12. Dataset secondhig** **is given as**

data secondhig; input Name $ Number; cards; sandeep 98 kuldeep 49 arvind 58 gajender 97 amit 69 ankit 97 abhishek 70 ; run;

Select those name having second highest numbers such that the output should be like:

Name Number

gajender 97

ankit 97

Answer: proc sql; select name, number from secondhig where number in (select max(Number) as second from secondhig where number<(select max(Number)from secondhig)); quit;

**Q13. ****I have a dataset concat having a variable a b & c. How to rename a b to e & f?**

We will use the following code to rename a b to e f

data concat(rename=(a=e b=f)); set concat; run;

**Q14. ****What are the statements in Proc SQl?**

Select, From, Where, Group By, Having, Order.

**Q15.** **Why and when do you use Proc SQl?**

Proc SQL is very convenient for performing table joins compared to a data step merge as it does not require the key columns to be sorted prior to join. A data step is more suitable for sequential observation-by-observation processing.

PROC SQL can save a great deal of time if u want to filter the variables while selecting or we can modify them, apply format and creating new variables, macro variables…as well as subsetting the data. PROC SQL offers great flexibility for joining tables.

** **

**Q16. ****What does the trace option do?**

ODS Trace is used to find the names of the particular output objects when several of them are created by some procedure.

**ODS** TRACE ON;

**ODS** TRACE Off;

** **

**Q17. How would you identify a macro variable?**

with Ampersand (&) sign

**Discuss Macro Variables & Functions For Beginners **

**Q18. How would you define the end of a macro?**

The end of the macro is defined by %Mend Statement

**Q19. What is the difference between %LOCAL and %GLOBAL?**

% Local is a macro variable defined inside a macro. %Global is a macro variable defined in open code (outside the macro or can use anywhere).

**Q20. How do you add a number to a macro variable**?

Using %eval function or %sysevalf function if the number is a floating number.

Q20. How we can call macros with in data step?

We can call the macro with

CALL SYMPUT,

Proc SQL ,

%LET statement. and macro parameters.

**Q21. ****What is interleaving in SAS?**

Interleaving combines individual, sorted SAS data sets into one sorted **SAS** data set. For each observation, the following figure shows the value of the variable by which the data sets are sorted. You interleave data sets using a SET statement along with a BY statement.

In the following example, the data sets are sorted by the variable Year.

We can sort and then join the datasets on Year with the below code.

Data combined; Set data1 data2 By Year; Run;

**Q22. Describe the ways in which you can create macro variables?**

There are the 5 ways to create macro variables:%Let

%Global

Call Symput

Proc SQl into clause

Macro Parameters.

**Tricky SAS Interview Questions For Freshers. Q- 14,15,17,18,19,21,22**

**Tricky SAS Interview Questions For Experienced. Q- 12,13,16,20**

**Q23. What is the maximum length of the macro variable?**

32 characters long.

** **

**Q24. **** What is Linear Regression?**

Linear regression is a statistical technique where the score of a variable Y is predicted from the score of a second variable X. X is referred to as the predictor variable and Y as the criterion variable.

**Read More About SAS Linear Regression with PROC REG Procedure**

**Q25. **** What do you understand by the term Normal Distribution?**

Data is usually distributed in different ways with a bias to the left or to the right or it can all be jumbled up. However, there are chances that data is distributed around a central value without any bias to the left or right and reaches normal distribution in the form of a bell-shaped curve. The random variables are distributed in the form of a symmetrical bell-shaped curve.

**Read about SAS Frequency Distribution Using SAS PROC FREQ**

**Q26. ****What does P-value signify about the statistical data?**

P-value is used to determine the significance of results after a hypothesis test in statistics. P-value helps the readers to draw conclusions and is always between 0 and 1.

- P- Value > 0.05 denotes weak evidence against the null hypothesis which means the null hypothesis cannot be rejected.
- P-value <= 0.05 denotes strong evidence against the null hypothesis which means the null hypothesis can be rejected.
- P-value=0.05is the marginal value indicating it is possible to go either way.

**Q27. ****How to create list output for cross-tabulations in proc freq?**

To generate list output for cross-tabulations, add a slash (/) and the LIST option to the TABLES statement in your PROC FREQ step.

TABLES variable-1*variable-2 < * … variable-n> / LIST;

**Q28. ****What is the difference between do while and do until?**

Main 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. But DO UNTIL executes at least once

**Q29**. **Difference between sum function and using “+” operator?**

SUM function returns the sum of non-missing arguments. ‘+’ operator returns a missing value if any of the arguments are missing.

** Refer This SAS Operators Guide to know more**

**Q30. ****What would be the result of the 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);**

Here, we will calculate the weeks between 31st December 2000 and 1st January 2001. 31st December 2000 was a Sunday. So 1st January 2001 will be a Monday in the same week. Hence, Weeks = 0

Years = 1 since both the days are in different calendar years.

Months = 1 since both the days are in different months of the calendar.

**Q31. ****Consider the following SAS Program:**

data concat; set a b; run;

**Where format of variable Revenue in dataset a is dollar10.2 and format of variable Revenue in dataset b is dollar12.2 . What would be the format of Revenue in resulting dataset (concat)?**

dollar10.2

The format will be the variable name ‘dollar’ which will be of length 10 numbers followed by two numbers after the decimal point.

**Tricky SAS Interview Questions For Freshers. Q- 23,24,25,26,**

**Tricky SAS Interview Questions For Experienced. Q- 27,28,29,30,31**

## 3. Summary

So these were some of the most Tricky SAS Interview Questions asked at an intermediate level and advanced level. Hope you all will be able to answer these Tricky SAS Interview Questions if asked in a SAS interview. Furthermore, if you have any query regarding Tricky SAS Interview Questions feel free to ask in a comment section.

See also –