Anda di halaman 1dari 16

SAS-INTERVIEW QUESTIONS

1. What SAS statements would you code to read an external raw


data file to a DATA step?

Ans: Infile and Input statements are used to read

O
external raw data file to a Data Step.

2. How do you read in the variable that you need?

EM
Ans: If we want to read a particular variable in a
set of SAS data set, we can mention the variable
we want in the INPUT statement.

3. Are you familiar with special input delimiters? How are


they used?

Ans: Yes, we have special delimiters like DLM and DSD

D
in SAS. Both these delimiters can be used in
the infile statement
The DLM can read the commas and spaces
as data delimiters. You may choose any delimiters
you wish with this option. You can choose
LS
multiple character such as DLM=”XX” for your
delimiter.
The DSD option allows you to treat two
consecutive delimiters as containing a missing
value.

4. If reading a variable length file with fixed input, how


O

would you prevent SAS from reading the next record if the
last variable didn’t have a value?

Ans: We can use MISS OVER option in the INFILE statement


O

5. What is the difference between an informat and a format?


Name three informat or format?
ST

Ans: An informat is an instruction that SAS uses to read


data values into a variable
A format is an instruction that SAS uses to write
data values

The three informat are: -


A) Date informat
SY

B) Character informat
c) Numeric informat

The three Formats are:-


data values left to be read from that line. The @@, therefore,
hold the input record even across multiple iteration of the
data step.

9. Under what circumstances would you code a SELECT construct


instead of IF statement?

Ans: Especially if you are recoding a variable into a

O
large number of categories.

10. What statement do you code to tell SAS that it is to


write to an external file?

EM
Ans: Filename fileref ‘path’;
File fileref;
Put _all_ /* will write all the variables. */
Or put the variables which you require.

11. If reading an external file to produce an external


file, what shortcut to write record without coding

D
every single variable on the record?

Ans: Put _all _


LS
12. If you do not want any SAS output from a data step, how
would you code the data statement to prevent SAS from
producing a set?

Ans: By using DATA _NULL_ the desired output is a file


and not a SAS dataset.
O

13. What is the one statement to set the criteria of a data


that can be coded in any step?

Ans: Options statement


O

14. Have you ever-linked SAS code? If so, describe the like
and any required statement used to either process the
ST

code or the step itself.

Ans : The link statement tells SAS to jump immediately


To the statement label that is indicated in the
Label statement and to continue executing
statements from that point until a RETURN
SY

statement is executed. The RETURN statement


ends program control to the statement immediately
following the LINK statement.
20. How would you code a merge that will keep only the
observation that have matches form both sets?

Ans: By using the IN internal variable in the merge


statement.

DATA NEW;
MERGE ONE_TEMP (IN=ONE) TWO_TEMP (IN=TWO);

O
BY NAME;
IF ONE=1 AND TWO=1;
RUN;

EM
21. What is the Program Data Vector (PDV)? What are their
functions?

Ans:
Program Data Vector is the temporary holding area.
For example The WHERE statement is may be more

D
efficient then the sub setting If (especially if you are
taking a very small sunset from a large file) because it
checks on the validity of the condition to see if the
observation is to be kept or not. This temporary holding
area is called the program data vector (PDV).
LS
22. Does SAS ‘Translate’ (compile) or does it ‘Interpret’?
Explain.

Ans: When you submit a DATA step for execution, SAS


checks the syntax of the SAS statements and compiles
O

them, that is, automatically translates the


statements into machine code. In this phase, SAS
identifies the type and length of each new variable,
and determines whether a type conversion is
O

necessary for each subsequent reference to a


variable.
ST

23. At compile time when a SAS data set is read, what


items are created?

Ans: At compile time SAS creates the following

A) Input Buffer
B) Program Data Vector(pdv)
SY

C) Descriptor information

24. Name statements that are recognized at compile time


32. What do the SAS log messages “numeric values have been
converted to character” mean?

Ans: If we try some character function on the numeric


values the SAS will automatically convert the
numeric variable into character variable.

33. Why is a STOP statement needed for a POINT=option on a SET

O
statement?

Ans: Because POINT= reads only the specified observations,


SAS cannot detect an end-of-file condition as itwould if the

EM
file were being read sequentially. Because detecting an end-of-
file condition terminates a DATA step automatically, failure to
substitute another means of terminating the DATA step when you
use POINT= can cause the DATA step to go into a continuous
loop.

NOTE:
You cannot use the POINT= option with any of the

D
following:

 BY statement
 WHERE statement
 WHERE= data set option
LS
 transport format data sets
 sequential data sets (on tape or disk)
 a table from another vendor's relational database
management system.

34. How do you control the number of observation and /or


O

variable read or write?

Ans: By specifying obs option


O

35. Approximately what date is represented by the SAS date


value of 730?

Ans: 1 January 1962.


ST

36. How would remove a format that has been permanently


associated with a variable.

Ans: By Using proc datasets library= somelibrary;


Modify sasdataset;
Run;
SY

37. What does the RUN statement do?


Ans: If we want to do a particular task for all the
numeric variable we can use the _numeric_ and same as
if we want to do a particular task for all the
character variable we can use the _character_

46. What is the order of application for output data set


option, input data set option and SAS statement?

O
Ans: INPUT data set option, SAS statement option and then
OUTPUT option.

EM
47. What is the order of evaluation of the comparison
operators: + - * /** ()?

Missing Value:

56. How many missing values are available? When might you use

D
them?

Ans: Two missing values are available in SAS, they are


numeric and character.
LS
57. How do you test for missing values?

Ans: We can test the missing values by using NMISS


option in the input statement

58. How are numeric and character missing values represented


O

internally?

Ans: The numeric missing values represented as dots(.) and


the character missing values represented as blank
O

FUNCTIONS:

59. What is the significance of the ‘OF’ in X=SUM (OF a1-a4,


ST

a6, a9);?

60. What do the PUT and INPUT function do?

Ans: The PUT function is used to identify the logic


Problem Which piece of code is executed and not
SY

executed what the current value of the particular


variable and what the current value of the all
variable.
63. In ARRAY processing, what does the DIM function do?

Ans: DIM is the dimension function. This returns the


length of the array (i.e. the number of variable in
the list).

O
64. How would you determine the number of missing or non-
missing value in computation?

Ans: We can use the N option for the number of NON-

EM
MISSING values and NMISS option for the number of
MISSING values.

65. What is the difference between: X=a+b+c+d; and X=SUM (a,


b, c, d);?

Ans: If we use SUM (a, b, c, d) it will ignore the missing

D
Values if any and compute the sum.

For E.G SUM(1,.,2,3)=6


X=1+.+2+3 = MISSING.
LS
66. There is a field containing a date. It needs to be
displayed in the format “ddmonyy” if it’s before 1975,”dd
mon ccyy” if it’s after 1985, and as ‘disco years’ if its
between 1975 and 1985. How would you accomplish this in
data step code? Using only PROC FORMAT.
O

67. In the following DATA step, what is needed for


‘fraction’to print to the log

Ans:
O

data _null_; X=1/3;


if X=.333 then ;
put ‘fraction’;
run;
ST

68. What is the difference between calculating the ‘mean’


using the mean function and PROC MEANS?

Ans: The mean function returns the mean of the non-missing


SY

values in the variable list. Actually, you may not


have figured out the importance of the way the MEAN
function deals with the missing values, and this is
quit important .if you calculate SCORE by simply
statistics for all subgroups, giving you all the
information in one run that you would get by
repeatedly sorting a data set by the variables that
define each subgroup and running PROC MEANS/.

2) PROC SUMMARY does not produce any information in


your output so you will always need to use the
OUTPUT statement to create a new data set and use

O
PROC PRINT to see the computed statistics.

EM
PROC FREQ:

73. Code the table statement for a single-level (most common)


frequency.

D
Ans
The statement for single-level.

DATA MAR.FREQTEST;
SET BAS.AMPERS;
LS
PROC FREQ DATA =MAR.FREQTEST;
TABLE AGE;
RUN;

74. Code the table statement to produce a multi-level


frequency.
O

Ans:
The statement for multilevel.

DATA MAR.FREQTEST;
O

SET BAS.AMPERS;
PROC FREQ DATA =MAR.FREQTEST;
TABLE AGE * gender;
RUN;
ST

75. Name the option to produce a frequency line items rather


that a table.

76. Produce output from a frequency. Restrict the printing of


the table.
SY
86. How do the IN= variable improve the capability of a
MERGE?

Ans: IN is a implicit variable in SAS which helps in


controlling which dataset needs to contribute to
the new dataset

87. Explain the message ‘MERGE HAS ONE OR MORE DATASETS WITH

O
REPEATS OF BY VARIABLE’.

COSTOMIZED REPORT WRITING:

EM
88. What is the purpose of the statement DATA_NULL_?

Ans:
Use the keyword _NULL_, which allows the power of the
DATA step without creating a data set.

D
89. What is the pound sign used for the DATA _NULL_?

90. What is the purpose of using the N=PS option?


LS
Ans: Specifying N=PS in the FILE statement allows
the output pointer to write on any line of the
current output
O

MACRO:
91. What system option would you use to help debug a macro?
O

Ans: Symbolgen Mlogic Mprint

92. Describe how you would create a macro variable?


ST

Ans: %let var=value;

93. How do you identify a macro variable?

94. How do you define the end of a macro?


SY

Ans: %mend

95. How do you assign a macro variable to a SAS variable?

Ans: Using CallSymput

Anda mungkin juga menyukai