# Base SAS Interview Questions and Answers Part – 3

#### 21. What’s the difference between VAR A1 – A3 and VAR A1 — A3?

Ans: Single Dash : It is used to specify consecutively numbered variables. A1-A3 implies A1, A2 and A3.

Double-dash : It is used to specify variables based on the order of the variables as they appear in the file, regardless of the name of the variable. A1–A3 implies all the variables from A1 to A3 in the order they appear in the data set.

Example : The order of variables in a data set : ID Name A1 A2 C1 A3

So using A1-A3 would return A1 A2 A3.
A1–A3 would return A1 A2 C1 A3.

#### 22. Difference between PROC MEANS and PROC SUMMARY?

Ans:

1. Proc MEANS by default produces printed output in the OUTPUT window whereas Proc SUMMARY does not. Inclusion of the PRINT option on the Proc SUMMARY statement will output results to the output window.

2. Omitting the var statement in PROC MEANS analyses all the numeric variable whereas Omitting the variable statement in PROC SUMMARY produces a simple count of observation.

How to produce output in the OUTPUT window using PROC SUMMARY?

Use PRINT option.

proc summary data = retail print;
class services;
var investment;
run;

#### 23. Can PROC MEANS analyze ONLY the character variables?

Ans: No, Proc Means requires at least one numeric variable.

#### 24. How SUBSTR function works?

Ans: The SUBSTR function is used to extract substring from a character variable.

The SUBSTR function has three arguments:

SUBSTR ( character variable, starting point to begin reading the variable, number of characters to read from the starting point)

There are two basic applications of the SUBSTR function:

RIGHT SIDE APPLICATION

data _null_ ;
phone = ‘(312) 555-1212’ ;
area_cd = substr(phone, 2, 3) ;
put area_cd = ;
run;

Result : In the log window, it writes area_cd = 312 .

LEFT SIDE APPLICATION

It is used to change just a few characters of a variable.

data _null_ ;
phone = ‘(312) 555-1212’ ;
substr(phone, 2, 3) = ‘773’ ;
put phone = ;
run ;

In this example, the variable PHONE has been changed from (312) 555-1212 to (773) 555-1212.

See the log window shown in the image below:

#### 25. Difference between CEIL and FLOOR functions?

Ans: The ceil function returns the smallest integer greater than/equal to the argument whereas the floor returns the greatest integer less than/equal to the argument.

For example : ceil(4.4) returns 5 whereas floor(4.4) returns 4.

#### 26. Difference between SET and MERGE?

Ans: SET concatenates the data sets where as MERGE matches the observations of the data sets.

SET

MERGE

#### 27. How to do Matched Merge and output only consisting of observations from both files?

Ans: Use IN= variable in MERGE statements. It is used for matched merge to track and select which observations in the data set from the merge statement will go to a new data set.

data readin;
merge file1(in=infile1) file2(in=infile2);
by id;
if infile1= infile2;
run;

#### 28. How to do Matched Merge and output consisting of observations in file1 but not in file2, or in file2 but not in file1?

Ans: data readin;
merge file1(in=infile1) file2(in=infile2);
by id;
if infile1 ne infile2;
run;

29. How to do Matched Merge and output consisting of observations from only file1?

Ans: data readin;
merge file1(in=infile1) file2(in=infile2);
by id;
if infile1;
run;

#### 30. How do I create a data set with observations =100, mean 0 and standard deviation 1?

Ans: data readin;
do i = 1 to 100;
temp = 0 + rannor(1) * 1;
output;
end;
run;

proc means data = readin mean stddev;
var temp;
run;