Vous êtes sur la page 1sur 13

SAS Questions

1.) Which is the correct statement:


a.) ODS HTML FILE = file;
b.) ODS FILE HTML = file
c.) ODS FILE = file
d.) ODS HTML = file
Answer: a
2.) Given the following code:
data temp;
length USUBJID $12.;
set lib1.x
lib2.y;
run;
What would be the length of USUBJID in temp?
a.) 5
b.) 8
c.) 12
d.) Syntax Error
Answer: c
3.) Given the following code:
proc sort data = lib.temp out = temp2;
by subjid;
run;
Temp2 is made in which library?
a.) WORK
b.) SASUSER
c.) LIB
d.) SYNTAX ERROR
Answer: a
4.) Given the following code:
options obs = 500;
data temp;
set test(firstobs = 75);
run;
What will be the number of observations in temp dataset?
a.)
424
b.)
425
c.)
500
d.)
75
e.)
426

Answer : e
5.) Given the following code and data values:
data temp;
merge X1 X2;
by ID;
run;
X1 DATASET

X2 DATASET

ID
1
2

ID
1
1
2
2

NAME
ALISON
KEVIN

CLASS
A
B
B
A

How many observations and variables will be there in temp dataset?


Answer: 4 observations 3 variables
6.) What is the correct MISSING CODE? Please note: dataset Test1 contains the variable USUBJID.
data temp; /*Test1 contains USUBJID */
MISSING CODE
By USUBJID;
run;
a.) Merge Test1
Test2(rename = (SUBJECT = USUBJID));
b.) Merge Test1
Test2(rename = (USUBJID = SUBJECT));
c.) Merge Test1 (rename = (SUBJECT = USUBJED))
Test2;
d.) Merge Test1
Test2(rename SUBJECT = USUBJID));
Answer: a
7.) Given the following code:
data temp;
test = X;
select(test);
when(Y) Name = Sus;
when(X) Name = Susheel;
when(Z) Name =
;
end;
run;
What is the value of Name in the resulting temp dataset?
a.) Susheel
b.) Sus
c.) Missing (character missing value)

d.) Susheel
Answer: b
7.) data _null_;
put Susheel;
run;
After execution of the data step above, where will the value from the put statement be written?
a.)
In Last file opened
b.)
In dataset _null_
c.)
Syntax error
d.)
Log
Answer: d
8.) What is true about _ERROR_ variable?
a.)
Can be used in assignments/calculation in a datastep.
b.)
This variable appears in the output dataset
c.)
Will have values YES or NO
d.)
Will have values TRUE or FALSE
Answer: a
9.) What is true about array variables?
a.)
They are temporary variables created in a datastep.
b.)
They are output in a dataset.
c.)
Can contain numeric and character values at same time.
d.)
Cannot be used in an assignment statement.
Answer: a
10.) Given the following code:
Data temp;
X= 13MAR2000d;
run;
What is stored in x?
a.)
13MAR2000
b.)
Corresponds to days from 01 Jan 1960: 14682
c.)
13/03/2000
d.)
Corresponds to days from 01 Jan 1960: 135680
Answer: b
11.)

1----5----10--- (data in file asa)


03132000
data temp;
infile asa;
input date : MMDDYY10.;
run;

What will be stored in date?


a.)
01022000
b.)
02FEB2000
c.)
14682(number of days from 1st jan 1960)
d.)
02 January
Answer: c
12.) Given the following code:
data test;
n=1;
do while(n lt 6);
n+1;
end;
run;
What will be the value of n at the end of datastep?
a.)
7
b.)
5
c.)
6
d.)
8
Answer: c
13.) Given the following code:
proc format;
value ag 1-50 = less
51-100 = greater;
run;
data test;
X = 50.5;
format x ag.;
run;
What will be the value of X in the dataset test?
a.) less
b.) greater
c.) great
d.) 50.5
e.) syntax error
Answer: d
14.) Given the following code:
data test;
dat = 13MAR2000d;
format dat WEEKDATE.;
run;
What will be the value of dat in output dataset?
a.) 13MAR2000

b.) Monday, March 13, 2000


c.) Mon, March 13, 2000
d.)14682 (nmber of days from 1st jan 1960)
Answer: b
15.) Given the following code:
data temp;
infile filename;
input ID $5 @;
if ID = RAMES then input Y $6 Z $10 @;
else ID = VIJAY then input R $2 @;
input age 5.;
run;
How many lines are read from input file during one execution of dataset?
a.)
2
b.)
1
c.)
3
d.)
4
Answer: b
16.) Given the FILE statements below, which is most appropriate when writing a comma separated file?
a.)
FILE filename dsd = ,;
b.)
FILE filename dlm = dsd = ,;
c.)
FILE filename dlm = ,;
d.)
FILE filename csv = ,;
Answer: c
17.)

1----5----10----15----(file abc)
RAM,,20
RAJU,SHARMA,24
data temp;
infile abc dsd;
input FNAME $ LNAME $ AGE;
run;
What will be the value of LNAME for 1st observation?
a.) ,
b.) blank character value
c.) SHARMA
d.) syntax error
Answer: b

18.) Given the following code:


data temp;
set test1(in=a) /* 2 observations*/
test2(in=b); /* 5 observations*/

if a and b;
run;
How many observations will be there in temp dataset?
a.) 2
b.) 5
c.) 7
d.) 0
Answer: d
19.) Given the following code:
libname temp abc.sds.as;
data temp.X1;
set sasuser.X2;
run;
Which is the correct statement?
a.) In datastep input is read from temporary location and output is written to temporary location.
b.) In datastep input is read from permanent location and output is written to temporary location.
c.) In datastep input is read from temporary location and output is written to permanent location.
d.) In datastep input is read from permanent location and output is written to permanent location.
Answer: d
20.) Given the following code:
1----5----10----15----20 (filename = abc)
ankur
22
data temp;
infile file;
input name $1-10 age 15-16;
/*missing code*/
run;
What is the missing code to write ankur,22 to variable LA;
a.) LA = TRIM(name)||,||put(Age,2.);
b.) LA = name||,||put(Age,2.);
c.) LA = name|| ,||TRIM(put(Age,2.));
d.) LA = put(name)||,||put(Age,3.);
Answer: a
21) Given the following code:
data temp;
merge test1(keep = ID)
test2(keep = ID NAME CLASS AGE);
by ID;
keep = ID NAME;
run;

What are the variables in the output dataset?


a.) ID NAME
b.) NAME ID
c.) ID NAME CLASS AGE
d.) The code results in an error
Answer: d
22.) Given the following code:
data a;
do X=1 to 3 ;
input ID NAME $ AGE;
end;
datalines;
01 vivek 22
02 vital 25
03 rajes 20
;
What will be the number of observations and variables in output dataset??
a.) 3 and 3
b.) 1 and 3
c.) 1 and 4
d.) 3 and 1
Answer: c
23) Flat file structure is as below
1----5----10
$1,120
The following code is submitted.
data temp;
infile file specification;
input salary 5;
run;
What would be the value of SALARY in the dataset TEMP?
a) $1,120
b) 2
c) (period)
d) Blank value
Answer: b
24) The following code is submitted
data temp;
length y $5;
x=4;
if x=4 then y='four';
else if x=7 then y='seven';
x=7;

run;
What would be the value of X and Y in the dataset temp?
a)
b)
c)
d)

X=4 and Y= seven


X=7 and Y=seven
X=7 and Y=four
X=4 and Y=four

Answer: c
25) Flat file structure is as below
1----5----10
dan 23 45
bob 44 50
sue 30 80
mam 40 50
The following code is submitted.
data temp;
infile file specification;
input x $ 1-3;
if x='sue' then input age 5-6;
else input height 8-9;
run;
What would be the value of variable AGE in the dataset TEMP when variable X has the value Sue?
a) 30
b) 44
c) 40
d) 55
Answer: c
26) Flat file structure is as below
1----5----10
vital reddy 45
vijay 30
sarma 40
The following code is submitted.
data temp;
infile file specification;
input x $ age;
if age<=40;
run;
How many observations will be there in the TEMP dataset?
a) 3
b) 2
c) zero observations
d) syntax error

Answer: d
27) The following code is submitted.
data temp;
SALARY='20000';
BONUS=0.1*SALARY;
run;
What would be the value of BONUS variable in the dataset TEMP?
a) 2000
b) 2000
c) .(period)
d) blank
Answer: b
28) The following code is submitted.
data temp;
SALARY=.;
if SALARY=. then SALARY=100;
BONUS=10;
SALARY=.;
total=sum(SALARY,BONUS);
run;
What would be the value of TOTAL variable in the dataset TEMP?
a) 100
b) 110
c) 10
d) .(period)
Answer: c
29) The following statement is submitted within a data step.
if 70<=AGE then call symput(cohort,other);
What is the name of the macro parameter created and what is its value?
a) &cohort; other
b) &other; cohort
c) @AGE; 70
d) syntax error
Answer: a
30) The dataset XYZ is as below
JOBCODE
Chem3
data xyz;

set temp;
if JOBCODE='CHEM3' then description='senior chemist';
else description='unknown';
run;
What is the value of DESCRIPTION variable in the TEMP dataset?
a) senior chemist
b) unknown
c) senior
d) blank characters
Answer: b
31) The following code is submitted.
data temp:
do i=1 to 3;
do j=1 to 4;
salary=salary+300;
end;
end;
run;
How many observations will present in the dataset temp?
a) 1
b) 3
c) 12
d) 0
Answer: a
32) Which of the following code creates the permanent dataset MYDATA from temporary dataset
MYDATA?
Libname out sas-library;
a) data MYDATA;
set MYDATA;
run;
b) data MYDATA;
set out.MYDATA;
run;
c) data out.MYDATA;
set MYDATA;
run;
d) none
Answer: c
33) See the code below
filename rawdata1 u3x2888.reddy.lib(reddy);
libname rawdata2 u3x2888.reddy.saslib
data temp;

infile missing code;


input x y;
run;
What should be inserted in place of missing code?
a) rawdata2
b) rawdata1
c) file
d) none
Answer: a
34) What is the procedure to print the data portion of the dataset?
a) PROC MEANS
b) PROC SQL
c) PROC PRINT
d) PROC CONTENTS
Answer: c
35) What is the procedure to see the descriptor portion of the dataset?
a) PROC MEANS
b) PROC SQL
c) PROC PRINT
d) PROC CONTENTS
Answer: d
36) The variable SUBJID has length $5 in the dataset temp. The same variable present in the dataset
temp1 and has length $7.
data temp2;
set temp temp1;
run;
What would be the length of the variable SUBJID in the dataset temp2?
a)
b)
c)
d)

5
7
We cant see the length because the data set wont be created due to errors.
None

Answer: a
37) Given the following code:
data temp;
x=4;
if x=5 then do;
y=2;
output;
end;

run;
How many observations will be there in output dataset temp?
a) 1
b) 2
c) 0
d) 3
Answer: c
38) Which variables will be present in dataset FINAL;
data FINAL;
set TRY1(keep= NUM1 NUM2 NUM3 NUM4)
TRY2(keep= NUM5 NUM6 NUM7 NUM8);
drop NUM2 NUM4 NUM7;
keep NUM1 NUM3;
run;
a)
b)
c)
d)

NUM1 NUM3 NUM5 NUM6 NUM8.


NUM1 NUM3;
Syntax error.
Warning in the log.

Answer: b
39) Given the following dataset:
SEX_______CITYCODE__________JOB
M
NY
WER
F
NY
WER
M
WD
RES
M
WD
RES
M
SD
ED
M
WF
ED
What will be the correct code to get a cross frequency table as following:
The FREQ Procedure
Table of SEX by CITYCODE
SEX

CITYCODE

Frequency
Percent
Row Pct
Col Pct NY
SD
WD
WF
Total

1
0
1
0
2
16.67 0.00 16.67 0.00 33.33
50.00 0.00 50.00 0.00
50.00 0.00 50.00 0.00

1
1
1
1
4
16.67 16.67 16.67 16.67 66.67
25.00 25.00 25.00 25.00
50.00 100.00 50.00 100.00

Total
2
1
2
1
6
33.33 16.67 33.33 16.67 100.00
a) proc freq data=A;
tables SEX*CITYCODE;
run;
b) proc freq data=A;
tables SEX CITYCODE;
run;
c) proc freq data =A;
tables SEX, CITYCODE;
run;
d) proc freq data =A;
var SEX CITYCODE;
run;
Answer: a
40) A data step merge is preferred over a SQL join when executing a many to many merge. True or
False?
a) True
b) False
Answer: b

Vous aimerez peut-être aussi