Sample SAS certification Questions
(Questions asked in Base SAS certification exam)
Values and names may be different:
1.)Which ODS command closes the HTML file??
Answer: ODS HTML CLOSE;
2.)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
3.)
data temp;
set lib1.x
lib2.y;
length jobcode $12.;
run;
What would be the length of Jobcode in temp?
a.)5
b.)8
c.)12
d.)Syntax Error
Answer: c
4.)
PROC SORT data = lib.temp out = temp2;
By subjid;
Run;
In which library temp2 is made?
a.)WORK
b.) SASUSER
c.)LIB
d.)SYNTAX ERROR
Answer: a
5.)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
6.) PROC SORT data = temp;
BY Descending JOBCODE SALARY;
RUN;
Temp DATASET
JOBCODESALARYAGE
X110020
X210010
X220020
A110010
A220010
A220040
What will be the output??
Answer:
Temp DATASET
JOBCODESALARYAGE
X210010
X220020
X110020
A220010
A220040
A110010
7.)
PROC SORT DATA = TEMP;
By Jobcode DESCENDING Salary;
RUN;
What will be the first observation? (Apply this on dataset created in last question)
Answer:
Temp DATASET
JOBCODESALARYAGE
A110010
A220010
A220040
X110020
X220020
X210010
8.)
DATA TEMP;
MERGE X1 X2;
BY ID;
RUN;
How many observations and variables will be there in temp dataset?
X1 DATASETX2 DATASET
IDNAMEIDCLASS
1ANKUR 1A
2VIJAY1B
2B
2A
Answer: 3 variables and 4 observations
9.)
DATA TEMP;
MISSING CODE
RUN;
What is the correct missing code?
a.)Merge Test1 /*Test1 contains JOBCODE */
Test2(rename = (Jcode = JOBCODE));
b.)Merge Test1 /*Test1 contains JOBCODE */
Test2(rename = (JOBCODE = JCODE));
c.)Merge Test1 (rename = (Jcode = JOBCODE)) /*Test1 contains JOBCODE */
Test2;
d.)Merge Test1 /*Test1 contains JOBCODE */
Test2(rename Jcode = JOBCODE));
Answer: a
10.) data temp;
test = ‘X’;
select(test);
when(‘Y’) Name = ‘Ank’;
when(‘X’) Name = ‘Ankur’;
when(‘Z’) Name = ‘ ’;
end;
run;
What is the output?
a.) Ankur
b.) Ank
c.) Missing (character missing value)
d.) ‘Ankur’
Answer: Good Question. I would suggest you to try this question on your system. The answer is b. Its because during compilation time the length of variable Name is set as 3 (see the first case ‘Y’) and hence even if the case ‘X’ is satisfied the output will still be Ank.
11.) data _null_;
put ‘ankur’;
run;
Where will the ouput(ankur) be written?
a.)In Last file opened
b.)In dataset _null_
c.)Syntax error
d.)Log
Answer: d
12.) What is true about _ERROR_ variable?
a.)Can be used in assignments/calculation in datastep.
b.)This variable appears in output dataset
c.)Will have values “YES” or “NO”
d.)Will have values “TRUE” or “FALSE”
Answer: a
13.) What is true about array variables?
a.)They are temporary variables created in datastep.
b.) They are output in dataset.
c.)Can contain numeric and character values at same time.
d.)Cannot be used in assignment statement.
Answer: b
14.) What is the system option to print TIME in OUTPUT window?
a.) DATETIME
b.) TIME
c.) DATE
d.) SECOND
Answer: c
15.) PROC Report question on difference between display and across.
16.) PROC Report question on difference between group and order.
17.)
DATA TEMP;
X= ‘13MAR2000’d;
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 (the choices mentioned in b and c points both were there. Hence I had to calculate the number of days from 01 Jan 1960. Although a rough idea will do. There was a digit difference between 2 options)
18.)
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 (Note: the date is stored in dataset as SAS date)
19.)
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 (Good Question again. This question will tell you that before marking any choice think twice. Actually it comes out of do while loop when n is 6 and will not execute the statement n+1;)
20.) GOOD QUESTION
Proc Format;
Value ag 1-50 = ‘less’
51-100 = ‘greater’;
Run;
Data test;
X = 50.5;
Format x ag.;
Run;
What will be the output of dataset test?
a.)‘less’
b.)‘greater’
c.)‘great’
d.)50.5
e.)systax error
Answer: d ( I would suggest please try it on your PC and check for different values. Whenever SAS does not find a mapping for some value in the format it print the value as it is.)
21.)
data test;
dat = ‘13MAR2000’d;
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
22.) data temp;
set x;
run;
“missing code”
data test;
set y;
run;
What will be the missing code to reset the page number ?
a.)OPTIONS PAGENO = 1;
b.)OPTIONS RESET PAGENO = 1;
c.)OPTIONS RESET PAGENUMBER = 1;
d.)OPTIONS PAGENUMBER = 1;
Answer: a
23.)
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 (note only one execution not complete dataset)
24.) How to write comma separated file?
a.)FILE ‘filename’ dsd = ‘,’;
b.)FILE ‘filename’ dlm = ‘ ’ dsd = ‘,’;
c.)FILE ‘filename’ dlm = ‘,’;
d.)FILE ‘filename’ csv = ‘,’;
Answer: c
25.)
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
26.)
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: 0 (Good question, repeated many times. Note a and b).
27.) data temp;
set test; /* 100 observations 20 for each ID*/
by ID;
if first,ID then name = ‘RAJU’;
else if ID = ‘RAM’ then name = ‘RAMU’;
if last.ID;
run;
How many observations will be present in temp dataset?
a.)5
b.)20
c.)100
d.)0
Answer: a
28.) Question on PROC PRINT with BY statement;
29.)
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
30.) What is the output of DATE9. format?
a.)11/31/2000
b.) 31/11/2000
c.) 31NOV2000
e.)01NOVEMBER2000
Answer: c
31.) Why PROC FSLIST is used?
a.)to write to an external file
b.)to read from an external file
c.)to sort by date
d.)not a valid statement
Answer: b
32.)
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.));
e.)LA = put(name)||’,’||put(Age,3.);
Answer: a
33.)
data temp;
merge test1(keep = ID)
test2(keep = ID NAME CLASS AGE);
by ID;
keep = ID NAME;
run;
Variables in output dataset?
A.)ID NAME
B.)NAME ID
C.)ID NAME CLASS AGE
D.)Syntax error
Answer: b
34.) 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
35) What informat should be used to read the date variable in the flat file having the values like 02NOV2003?
a)DATE9.
b)MMDDYY8.
c)MMDDYY10.
d) none
Answer: a
36) 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
Ans: b
Tip: Here the SAS goes to the 5th column and read the value. But if we specify the informat like SALARY 5. then there will be ‘.’ In the SALARY variable. Please keep in mind that if there is any data error, SAS produces blank values to those variables(i.e ‘.’ For numeric variables and blank for the character variables). SAS never stops execution when data error occurs.
37) Flat file structure is as below
1----5----10
02032000
The following code is submitted.
data temp;
infile ‘file specification’;
input date mmddyy10.;
run;
what is the value of date in the dataset TEMP?
a)02032000
b) 14643, the number of days from jan 1st , 1960
c) 1460000, the number of days from jan 1st , 1960
d) 02/03/2000
Ans: b
38) The following code is submitted
data temp;
x=14643;
y=put(x,mmddyy10.);
run;
What would be the attributes of variable Y in the dataset TEMP?
a) Length of Y is $10.
b)Length of Y is 10
c)Length of Y is 8
d)None
Ans: a
39) 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)X=4 and Y= ‘seven’
b)X=7 and Y=’seven’
c)X=7 and Y=’four’
d)X=4 and Y=’four’
Ans: c
40) 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
Ans: c
41) Flat file structure is as below (Very good question)
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
Ans: a
42) 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
Ans: b
43) 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)
Ans: c
44) The descriptor portion of the dataset TEMP has the label of variable SALARY as ‘Actual salary’. which of the below code changes the label of the variable SALARY to ‘given’?
a)
proc print data=temp label;
label salary='given';
run;
b)
proc print data=temp label;
label salary 'given';
run;
c)
proc print data=temp;
label salary 'given';
run;
d)
proc print data=temp;
label salary='given';
run;
Ans: a
45) 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
Ans: b
Tip: here we need to use UPCASE (jobcode) in if statement as the character comparison is case sensitive.
46) The TEMP dataset has the values of variables as below
X Y Z
150 less than 200 and gt 100 300
which of the below code creates the dataset TEMP with above values in the variables X, Y, and Z.
a)
data temp;
x=150;
if 100 le x le 200 then do;
y='less than 200 and gt 100';
z=300;
end;
else do;
y='other values';
z=400;
end;
run;
b)
data temp;
x=150;
if 100 le x le 200 then do;
y='less than 200 and gt 100';
z=300;
else do;
y='other values';
z=400;
end;
run;
c)
data temp;
x=150;
if 100 le x le 200 then
y='less than 200 and gt 100';
z=300;
else do;
y='other values';
z=400;
end;
run;
d) None
Ans: a
47) Flat file structure is as below
1----5----10
23 44
The following code is submitted.
data temp;
infile ‘file specification’;
input @1 weight 2. @4 height 2.;
run;
What is the value of HEIGHT variable in the TEMP dataset?
a). (period)
b)Blank
c)44
d)23
48) 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)2
d)0
Ans: a
49) The dataset XYZ has 5000 observations.
options obs=500;
proc print data=xyz(firstobs=100 )
run;
options obs=max;
proc means data=xyz(firstobs=500)
run;
How many observations processed in each procedure?
a) 401 in the proc print and 4501 in the proc means
b) 5000 in the proc print and 500 in the proc means
c) 500 in the proc print and 5000 in the proc means
d) 4501 in the proc print and 401 in the proc means
Ans: a
50) Which of the following code calculates the mean of variables var1, var2, var3, and var4.
a)MEAN(var1-var4)
b)MEAN(of var1-var4)
c)MEAN(var1 var2 var3 var4)
d)MEAN(var1)
Ans: b
51) 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
Ans: c
52) 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
Ans: b
53) what is the procedure to print the data portion of the dataset?
a)PROC MEANS
b)PROC SQL
c)PROC PRINT
d)PROC CONTENTS
Ans: c
54) what is the procedure to see the descriptor portion of the dataset?
a)PROC MEANS
b)PROC SQL
c)PROC PRINT
d)PROC CONTENTS
Ans: d
55) The variable JOBCODE 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 JOBCODE in the dataset TEMP2?
a)5
b)7
c)we can’t see the length as data set won’t be created due to errors.
d)None
Ans: a
Tip: whenever we are concatenating the datasets which are having the same variable names but having the difference in the attributes like Label, length etc.. will be taken from the first dataset that has occurred in the SET statement. Here it is TEMP dataset.
56) one question on using same variable in the ID and BY statement of PROC PRINT.
57) What will be the value of variable b in the log when following datastep is submitted? Today’s date is 31DEC2004;
Data _NULL_;
a=month(today());
b=put(a,date9.);
put b;
run;
a)13JAN1960;
b)syntax error
c)31DEC2004
d)12
Ans:a
58) Data a has 12 observations and one variable Date as following.
Date______
01/01/2004
02/01/2004
03/02/2004
04/01/2004
05/01/2004
06/01/2004
07/01/2004
08/01/2004
09/01/2004
10/01/2004
11/01/2004
12/01/2004
How many observations will be there dataset b if the following datastep is submitted?
Data b;
Set a;
Temp = qtr(input(Date,mmddyy10.));
If Temp LE 3;
RUN;
A)3
B)5
C)9
D)6
Ans: D
59) What will be the length of variable LEN when the following code is submitted?
Data temp;
A = ‘I am Bond, James Bond’;
LEN=SCAN(A,3);
Run;
a)4
b)20
c)8
d)200
Ans: d
60) What will be the value of variable LEN when the following code is submitted?
Date temp;
A=’I was Bond, A real Bond’;
LEN=SUBSTR(A,6,4);
Run;
a)4
b)23
c)1
d)200
Ans: b
Note: Whenever a variable is created by assigning the value returned by the SCAN function, Its length is always $200 ( If it is not set explicitly using length statement). Similarly when a variable is created by assigning the value returned by the SUBSTR function, Its length is same as the source string no matter how many character did you cut from the original string. TRANWRD and COMPBL are the other two functions which return the value of length 200.
61) How many observations will be there in output dataset temp?
data temp;
x=4;
if x=5 then do;
y=2;
output;
end;
run;
a)1
b)2
c)0
d)3
Ans: c
62) 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)NUM1 NUM3 NUM5 NUM6 NUM8.
B)NUM1 NUM3;
C)Syntax Error.
D)Warning in the log.
Ans:b
63) A 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
ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ
F ‚ 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 ‚
ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ
M ‚ 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;
Ans: a
Suggestions:
1.)Please Go Through Programming Essentials I And II before appearing In Exam.
2.)Practice well to differentiate between the cases of Syntax Error and Missing value. This will help you achieving good score in Handling Errors.
Jan30-06
1.
Raw data file given is
----|----
01012000
data temp;
infile 'file';
input date mmddyy10.;
if date='01012000'd then EVENT='January 1st'.
run;
What is the value of EVENT in the dataset?
a) January 1st
b) '' (blank character value)
c) no value as there is a syntax error in the datastep
d) 01012000
ans c) as date constant uses ddmmmyyyy format i.e. date='01jan2000'd is the correct option here.
2. Array name related conceptual question
3.
data temp;
infile 'file';
input relation $ @;
if relation='children' then
input sex $54;
else if relation='parent' then
input profession $;
input Age;
run;
how many records from infile will be read for a record in the dataset?
a) 0
b) 1
c) 2
d) 3
ans 1
4.
data temp;
infile 'file';
retain address {12};
array address {12} address1-address12;
run;
how many observations??
a) 0
b) 1
c) 2
d) 3
ans a (syntax error - error in retain statement)
5. proc sort data=temp;
by style;
run;
proc print data=temp;
<insert statements here for the exhibit shown>
run;
Style
CondoBedrooms50.158
Baths12.225
RanchBedrooms25.212
Baths2.22
SplitBedrooms124.55
Baths120.22
a) id style;
by style;
var style bedrooms baths price;
b) id style
ans a
6. What should be the code for the exhibit shown below:
proc report data=temp;
columns style bedrooms baths price;
<insert code>;
run;
(Dataset is also shown and the values of price in the exhibit is not mean)
Style Price
CondoBedrooms50.158
Baths12.225
RanchBedrooms25.212
Baths2.22
SplitBedrooms124.55
Baths120.22
a) define style/display width=9;
define price/sum width=9;
b) define style/display width=9;
define price/mean width=9;
ans a
7. which statement creates grandtotal of cost?
a) grandtot=grandtot+cost;
b) retain grandtot=0;
grandtot=sum(grandtot, cost);
c) retain grandtot;
ans b
8. Theory question related to SUM statement (not sum function)
which is true for the SUM statement?
a) SUM function is used in conjunction
b) it creates an accumulator variable
9. Question on PROC REPORT which uses mean of Price (given in the exhibit)- verify the values of price in dataset with the exhibit to identify the statistics used.
10. which option limits the decimals for standard deviation in the proc below to 2 decimals
proc means data=temp mean std max;
run;
a) maxdec=2
b) format std 7.2
c) maxdec= 7.2
ans a
11. data temp;
jobcode='FA'
jobcategory='1';
jobcode=jobcode||jobcategory;
run;
what wud be value of jobcode
ans FA
12. data temp;
str='London, England';
str2=substr(str, 1, 8);
str3=str2||'England';
run;
value of str3?
a) London, England
b) England
c) London, England
ans a
13. Usage of Display option in DEFINE statement in PROC REPORT.
14. Input file has
----|--
$1,120
data temp;
infile 'file';