SAS Programming Concepts, Exams of Computer Science

Various sas programming concepts, including accessing sas files, reading delimited files, handling errors, working with libraries and fileref, and using proc import and proc print statements. It provides explanations and examples related to sas data manipulation, data management, and output generation. Likely intended for sas users, students, or professionals who are learning or working with the sas programming language. It covers a range of topics that are fundamental to sas programming, making it a potentially useful resource for understanding and applying sas techniques in data analysis, reporting, and automation.

Typology: Exams

2023/2024

Available from 09/20/2024

ROCKY-B
ROCKY-B 🇰🇪

4.4

(16)

40K documents

1 / 29

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
SAS PROGRAMMING CERTIFICATION TEST
QUESTIONS
13.2 What is an advantage of storing dates and times as SAS numeric date and time
values?
a. They can easily be edited.
b. They can easily be read and understood.
c. They can be used in text strings like other character values.
d. They can be used in calculations like other numeric values. - Answers -Correct
answer: d
In addition to tracking time intervals, SAS date and time values can be used in
calculations like other numeric values
2.2 How many program steps are executed when the program below is processed?
data user.tables;
set work.jobs;
run;
proc sort data=user.tables;
by name;
run;
proc print data=user.tables;
run;
A. 3
B. 4
C. 5
D. 6 - Answers -Correct answer: a
When it encounters a DATA, PROC, or RUN statement, SAS stops reading statements
and executes the previous step in the program. This program contains one DATA step
and two PROC steps, for a total of three program step
2.5 With the system option VALIDVARNAME=ANY, which of the following variable
names is valid?
a. 4BirthDate
b. $Cost
c. _Items_
d. Tax-Rate
e. All of the above - Answers -Correct answer: e
If you use VALIDVARNAME=ANY, the name can begin with or contain any characters,
including blanks, national characters, special characters, and multi-byte characters. The
name can be up to 32 bytes long. The name must contain at least one character, and
the variable name can contain mixed-case letters
2.6 Which of the following files is a permanent SAS file?
a. Work.PrdSale
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d

Partial preview of the text

Download SAS Programming Concepts and more Exams Computer Science in PDF only on Docsity!

SAS PROGRAMMING CERTIFICATION TEST

QUESTIONS

13.2 What is an advantage of storing dates and times as SAS numeric date and time values? a. They can easily be edited. b. They can easily be read and understood. c. They can be used in text strings like other character values. d. They can be used in calculations like other numeric values. - Answers -Correct answer: d In addition to tracking time intervals, SAS date and time values can be used in calculations like other numeric values 2.2 How many program steps are executed when the program below is processed? data user.tables; set work.jobs; run; proc sort data=user.tables; by name; run; proc print data=user.tables; run; A. 3 B. 4 C. 5 D. 6 - Answers -Correct answer: a When it encounters a DATA, PROC, or RUN statement, SAS stops reading statements and executes the previous step in the program. This program contains one DATA step and two PROC steps, for a total of three program step 2.5 With the system option VALIDVARNAME=ANY, which of the following variable names is valid? a. 4BirthDate b. $Cost c. Items d. Tax-Rate e. All of the above - Answers -Correct answer: e If you use VALIDVARNAME=ANY, the name can begin with or contain any characters, including blanks, national characters, special characters, and multi-byte characters. The name can be up to 32 bytes long. The name must contain at least one character, and the variable name can contain mixed-case letters 2.6 Which of the following files is a permanent SAS file? a. Work.PrdSale

b. Cert.MySales c. Certxl.Quarter d. only b and c above e. all of the above - Answers -Correct answer: d To store a file permanently in a SAS data library, you assign it a libref. For example, by assigning the libref Cert to a SAS data library, you specify that files within the library are to be stored until you delete them. Therefore, SAS files in the Cert and Certxl libraries are permanent files 2.7 In a DATA step, how can you reference a temporary SAS data set named Forecast? a. Forecast b. Work.Forecast c. Sales.Forecast (after assigning the libref Sales) d. only a and b above - Answers -Correct answer: d To reference a temporary SAS file in a DATA step or PROC step, you can specify the one-level name of the file (for example, Forecast) or the two-level name using the libref Work (for example, Work.Forecast). 3.1 How long do librefs remain in effect? a. until the LIBNAME statement is changed b. until the LIBNAME statement is canceled c. until the SAS session ends d. All of the above - Answers -Correct answer: d Librefs remain in effect until the LIBNAME statement is changed, canceled, or until the SAS session ends 3.2 Which of the following statements are true? a. When using the default engine, you do not have to specify the libref in the LIBNAME statement. b. When using the default engine, you do not have to specify the engine name in the LIBNAME statement. c. When using the default engine, you do not have to specify the SAS library in the LIBNAME statement. d. When using the default engine, you have to specify the libref, engine name, and the SAS library in the LIBNAME statement. - Answers -Correct answer: b When you are using the default engine, you do not have to specify the engine name in the LIBNAME statement. However, you do have to specify the libref and the SAS data library name. 3.3 When you specify an engine for a library, what are you specifying? a. the file format for files that are stored in the library b. the version of SAS that you are using c. access to other software vendors' files d. instructions for creating temporary SAS files - Answers -Correct answer: a A SAS engine is a set of internal instructions that SAS uses for writing to and reading from files in a SAS library. Each engine specifies the file format for files that are stored

c. Librefs can last from one SAS session to another. d. You can access files that were created with other vendors' software by submitting a LIBNAME statement. - Answers -Correct answer: c The LIBNAME statement is global, which means that librefs stay in effect until changed or canceled, or until the SAS session ends 3.8 What does the following statement do? libname states 'c:\myfiles\sasdata\popstats'; a. defines a library called States using the Popstats engine b. defines a library called Popstats using the States engine c. defines the default library using the default engines d. defines a library called States using the default engine - Answers -Correct answer: d The LIBNAME statement does not specify an engine. Therefore, it uses a default engine to create the States library 4.1 Which SAS statement associates the fileref Crime with the raw data file C:\States
Data\crime.dat? a. filename crime 'c:\states\data\crime.dat'; b. filename crime c:\states\data\crime.dat; c. fileref crime 'c:\states\data\crime.dat'; d. filename 'c:\states\data\crime' crime.dat; - Answers -Correct answer: a You assign a fileref by using a FILENAME statement in the same way that you assign a libref by using a LIBNAME statement 4.2 Which type of delimited file does PROC IMPORT read by default? a. logical record-length files b. varying record-length files c. fixed record-length files d. illogical record-length files - Answers -Correct answer: b By default, the IMPORT procedure reads delimited files as varying record-length files 4.3 Which program correctly imports only the first seven observations from the external file? a. options obs=7; proc import data="C:\users\test.txt" out=exam dbms=dlm replace; run; proc print data=exam; run; b. proc import datafile="c:\users\test.txt" out=exam dbms=dlm replace; options obs=7;

run; proc print data=exam; run; c. proc import datafile="c:\users\test.txt" out=exam dbms=dlm replace; run; proc print data=exam (obs=7); run; d. proc import datafile="c:\users\test.txt" out=exam dbms=dlm replace; run; proc print data=exam; options obs=7; run; - Answers -Correct answer: a Use the OBS= option in the OPTIONS statement before the IMPORT procedure to limit the number of observations that SAS reads from the external file 2.9 How many statements does the following SAS program contain? proc print data=cert.admit label double; var ID Name Sex Age; where Sex=F; label Sex='Gender'; run; a. three b. four c. five d. six - Answers -Correct answer: c The five statements are 1) the PROC PRINT statement (two lines long); 2) the VAR statement; 3) the WHERE statement (on the same line as the VAR statement); 4) the LABEL statement; and 5) the RUN statement (on the same line as the LABEL statement). 2.10 What is a SAS library? a. a collection of SAS files, such as SAS data sets and catalogs b. in some operating environments, a physical collection of SAS files c. a group of SAS files in the same folder or directory d. all of the above - Answers -Correct answer: d Every SAS file is stored in a SAS library. A SAS library is a collection of SAS files, such as SAS data sets and catalogs. In some operating environments, a SAS library is a physical collection of files. In others, the files are only logically related. In the Windows

b. • Correct the errors. • Resubmit the program. • Check the Output window. • Check the SAS log. c. • Correct the errors. • Clear the SAS log. • Resubmit the program. • Check the Output window. d. • Correct the errors. • Clear the Outputwindow. • Resubmit the program. • Check the Output window. - Answers -Correct answer: a To correct errors in programs when you use the Editor window, you usually need to recall the submitted statements from the recall buffer to the Editor window 5.2 What happens if you submit the following program? proc sort data=cert.stress out=maxrates; by maxhr; run; proc print data=maxrates label double noobs; label rechr='Recovery Heart Rate; var resthr maxhr rechr date; where toler='I' and resthr>90; sum fee; run; a. SAS log messages indicate that the program ran successfully. b. A PROC SORT running message appears at the top of the active window, and a log message might indicate an error in a statement that seems to be valid. c. A SAS log message indicates that an option is not valid or not recognized. d. A PROC PRINT running message appears at the top of the active window, and a SAS log message might indicate that a quoted string has become too long or that the statement is ambiguous. - Answers -Correct answer: d The missing quotation mark in the LABEL statement causes SAS to misinterpret the statements in the program 5.3 What generally happens when a syntax error is detected? a. SAS continues processing the step. b. SAS continues to process the step, and the SAS log displays messages about the error. c. SAS stops processing the step in which the error occurred, and the SAS log displays messages about the error. d. SAS stops processing the step in which the error occurred, and the Output window displays messages about the error. - Answers -Correct answer: c Syntax errors generally cause SAS to stop processing the step in which the error occurred 5.4 A syntax error occurs during the following actions: a. Some data values are not appropriate for the SAS statements that are specified in a program. b. The form of the elements in a SAS statement is correct, but the elements are not valid for that usage. c. Program statements do not conform to the rules of the SAS language. d. None of the above. - Answers -Correct answer: c

Syntax errors occur because the program statements did not conform to the rules of the SAS language 5.5 How can you tell whether you have specified an invalid option in a SAS program? a. A SAS log message indicates an error in a statement that seems to be valid. b. A SAS log message indicates that an option is not valid or not recognized. c. The message PROC STEP running or DATA STEP running appears at the top of the active window. d. You cannot tell until you view the output from the program. - Answers -Correct answer: b When you submit a SAS statement that contains an invalid option, a log message notifies you that the option is not valid or not recognized 5.6 Which of the following programs contains a syntax error? a. proc sort data=cert.mysales; by region; run; b. dat work.mysales; set cert.sales17; where sales<5000; run; c. proc print data=work.mysales label; label region='Sales Region'; run; d. None of the above. - Answers -Correct answer: b The DATA step contains a misspelled keyword (dat instead of data). 5.7 What should you do after submitting the following program in the Windows or UNIX operating environment? proc print data=mysales; where state='NC; run; a. Submit a RUN statement to complete the PROC step. b. Recall the program. Then add a quotation mark and resubmit the corrected program. c. Cancel the submitted statements. Then recall the program, add a quotation mark, and resubmit the corrected program. d. Recall the program. Then replace the invalid option and resubmit the corrected program. - Answers -Correct answer: c This program contains an unbalanced quotation mark. When you have an unbalanced quotation mark, SAS is often unable to detect the end of the statement in which it occurs 5.8 Suppose you submit a short, simple DATA step. If the active window displays the message DATA step running for a long time, what probably happened? a. You misspelled a keyword. b. You forgot to end the DATA step with a RUN statement.

run; c. proc sort data=finance.dividend out=work.calc; by account; run; d. proc sort from finance.dividend to calc; by account; run; - Answers -Correct answer: c In a PROC SORT step, you specify the DATA= option to specify the data set to sort 6.6 What happens if you submit the following program? proc sort data=cert.diabetes; run; proc print data=cert.diabetes; var age height weight pulse; where sex='F'; run; a. The PROC PRINT step runs successfully, printing observations in their sorted order. b. The PROC SORT step permanently sorts the input data set. c. The PROC SORT step generates errors and stops processing, but the PROC PRINT step runs successfully, printing observations in their original (unsorted) order. d. The PROC SORT step runs successfully, but the PROC PRINT step generates errors and stops processing. - Answers -Correct answer: c The BY statement is required in PROC SORT 6.8 Which statement below selects rows that satisfy both these conditions?

  • The amount is less than or equal to $5000.
  • The account is 101-1092 or the rate equals 0.095. a. where amount <= 5000 and account='101-1092' or rate = 0.095; b. where (amount le 5000 and account='101-1092') or rate = 0.095; c. where amount <= 5000 and (account='101-1092' or rate eq 0.095); d. where amount <= 5000 or account='101-1092' and rate = 0.095; - Answers -Correct answer: c To ensure that the compound expression is evaluated correctly, you can use parentheses to group the observations: account='101-1092' or rate eq 0. 6.9 What does PROC PRINT display by default? a. PROC PRINT does not create a default report; you must specify the rows and columns to be displayed. b. PROC PRINT displays all observations and variables in the data set. If you want an additional column for observation numbers, you can request it.

c. PROC PRINT displays columns in the following order: a column for observation numbers, all character variables, and all numeric variables. d. PROC PRINT displays all observations and variables in the data set, a column for observation numbers on the far left, and variables in the order in which they occur in the data set. - Answers -Correct answer: d By default, PROC PRINT prints all observations and variables. 7.1 Which of the following is not written to the output during the compilation phase? a. the data set descriptor b. the first observation c. the program data vector d. the N and ERROR automatic variables - Answers -Correct answer: b During the compilation phase, the program data vector is 7.2 During the compilation phase, SAS scans each statement in the DATA step, looking for syntax errors. Which of the following is not considered a syntax error? a. incorrect values and formats b. invalid options or variable names c. missing or invalid punctuation d. missing or misspelled keywords - Answers -Correct answer: a Syntax checking can detect many common errors, but it cannot verify the values of variables or the correctness of formats 7.3 Unless otherwise directed, how does the DATA step execute? a. once for each compilation phase b. once for each DATA step statement c. once for each record in the input file d. once for each variable in the input file - Answers -Correct answer: c The DATA step executes once for each record in the input file, unless otherwise directed 7.4 At the beginning of the execution phase, the value of N is 1, the value of ERROR is 0, and the values of the remaining variables are set to the following: a. 0 b. 1 c. undefined d. missing - Answers -Correct answer: d The remaining variables are initialized to missing. Missing numeric values are represented by periods, and missing character values are represented by blanks 7.5 Suppose you run a program that causes three DATA step errors. What is the value of the automatic variable ERROR when the observation that contains the third error is processed? a. 0 b. 1 c. 2

The FREQ procedure detects invalid character and numeric values by looking at distinct values 7.11 At the start of DATA step processing, during the compilation phase, variables are created in the program data vector (PDV), and observations are set to which of the following: a. blank. b. missing. c. 0. d. there are no observation - Answers -Correct answer: d At the bottom of the DATA step, the compilation phase is complete, and the descriptor portion of the new SAS data set is created 8.1 Which of the following statements is false when you use the BY statement with the SET statement? a. The data sets listed in the SET statement must be indexed or sorted by the values of the BY variable or variables. b. The DATA step automatically creates two variables, FIRST. and LAST., for each variable in the BY statement. c. FIRST. and LAST. identify the first and last observation in each BY group, respectively. d. FIRST. and LAST. are stored in the data set. - Answers -Correct answer: d When you use the BY statement with the SET statement, the DATA step creates the temporary variables FIRST. and LAST 8.2 Your data does not require any preprocessing if the observations in all of the data sets occur in which of the following patterns? a. Ascending or descending character order. b. Ascending or descending numeric order. c. The data must be grouped in some way. d. All of the above - Answers -Correct answer: d Before you can perform BY-group processing, your data must follow a patter 8.3 Which temporary variables are available for DATA step programming during BYgroup processing only, but are not added to the data set? a. FIRST.variable and LAST.variable. b. N and _ERROR variables. c. Both a and b. d. None of the above. - Answers -Correct answer: a In the DATA step, during BY-group processing only, the temporary variables FIRST.variable and LAST.variable are available for DATA step programming 8.5 What statement correctly describes a BY group? a. It contains temporary variables that SAS creates for each BY variable. b. It includes all observations with the same BY value. c. It names a variable or variables by which the data set is sorted.

d. It is a method of processing observations from one or more SAS data sets that are group or ordered by one or more common variables. - Answers -Correct answer: b A BY group includes all observations with the same BY value 8.6 How does SAS determine FIRST.variable? a. When an observation is the first in a BY group, SAS sets the value of the FIRST.variable to 1. This happens when the value of the variable changed from the previous observation. b. For all other observations in the BY group, the value of FIRST.variable is 0. c. Both a and b. d. When an observation is the last in a BY group, SAS sets the value of FIRST.variable to 1. - Answers -Correct answer: c SAS determines FIRST.variable by looking at each observation 9.2 Consider the IF-THEN statement shown below. When the statement is executed, which expression is evaluated first? if finlexam>= and (research='A' or (project='A' and present='A')) then Grade='A+'; a. finlexam>= b. research='A' c. project='A' and present='A' d. research='A' or (project='A' and present='A') - Answers -Correct answer: c Logical comparisons that are enclosed in parentheses are evaluated as true or false before they are compared to other expressions 9.4 Which of the following can determine the length of a new variable? a. the length of the variable's first reference in the DATA step b. the assignment statement c. the LENGTH statement d. all of the above - Answers -Correct answer: d The length of a variable is determined by its first reference in the DATA step 9.5 Which set of statements is equivalent to the code shown below? if code='1' then Type='Fixed'; if code='2' then Type='Variable'; if code^='1' and code^='2' then Type='Unknown'; a. if code='1' then Type='Fixed'; else if code='2' then Type='Variable'; else Type='Unknown'; b. if code='1' then Type='Fixed'; if code='2' then Type='Variable'; else Type='Unknown'; c. if code='1' then type='Fixed'; else code='2' and type='Variable';

a. none b. Weight c. Age, Group d. Age, Weight, Group - Answers -Correct answer: b The variables Age, Weight, and Group are specified using the KEEP= option in the SET statement The DATA statement is where it is written, and the SET statement is what is read 9.9 Which of the following programs correctly reads the data set Orders and creates the data set FastOrdr? a. data cert.fastordr(drop=ordrtime); set cert.orders(keep=product units price); if ordrtime<4; Total=unitsprice; run; b. data cert.orders(drop=ordrtime); set cert.fastordr(keep=product units price); if ordrtime<4; Total=unitsprice; run; c. data cert.fastordr(drop=ordrtime); set cert.orders(keep=product units price ordrtime); if ordrtime<4; Total=units*price; run; d. none of the above - Answers -Correct answer: a You can't drop variables kept in the set statement when creating a new dataset in the data step 10.7 The data sets Cert.Spring and Cert.Sum both contain a variable named Blue. How do you prevent the values of the variable Blue from being overwritten when you merge the two data sets? a. data work.merged; merge cert.spring(in=blue) cert.summer; by fabric; run; b. data work.merged; merge cert.spring(out=blue) cert.summer; by fabric; run; c. data work.merged; merge cert.spring(blue=navy) cert.summer; by fabric;

run; d. data work.merged; merge cert.spring(rename=(blue=navy)) cert.summer; by fabric; run; - Answers -Correct answer: d Match-merging overwrites same-named variables in the first data set with samenamed variables in subsequent data sets 11.1 Which statement is false regarding the use of DO loops? a. They can contain conditional clauses. b. They can generate multiple observations. c. They can be used to combine DATA and PROC steps. d. They can be used to read data. - Answers -Correct answer: c DO loops are DATA step statements and cannot be used in conjunction with PROC steps 11.2 During each execution of the following DO loop, the value of Earned is calculated and is added to its previous value. How many times does this DO loop execute? data work.earnings; Amount=1000; Rate=.075/12; do month=1 to 12; Earned+(amount+earned)rate; end; run; a. 0 b. 1 c. 12 d. 13 - Answers -Correct answer: c The number of iterations is determined by the DO statement's stop value, which in this case is 12 11.3 On January 1 of each year, $5,000 is invested in an account. Complete the DATA step below to determine the value of the account after 15 years if a constant interest rate of 10% is expected. data work.invest; ... Capital+5000; capital+(capital.10); end; run; a. do count=1 to 15; b. do count=1 to 15 by 10%; c. do count=1 to capital; d. do count=capital to (capital*.10); - Answers -Correct answer: a Use a DO loop to perform repetitive calculations starting at 1 and looping 15 times

11.7 Which of the following would you use to compare the result of investing $4,000 a year for five years in three different banks that compound interest monthly? Assume a fixed rate for the five-year period. a. DO WHILE statement b. nested DO loops c. DO UNTIL statement d. a DO group - Answers -Correct answer: b Place the monthly calculation in a DO loop within a DO loop that iterates once for each year 11.8 Which statement is false regarding DO UNTIL statements? a. The condition is evaluated at the top of the loop, before the enclosed statements are executed. b. The enclosed statements are always executed at least once. c. SAS statements in the DO loop are executed until the specified condition is true. d. The DO loop must have a closing END statement. - Answers -Correct answer: a The DO UNTIL condition is evaluated at the bottom of the loop, so the enclosed statements are always executed at least once 11.9 Select the DO WHILE statement that would generate the same result as the program below. data work.invest; capital=100000; do until(Capital gt 500000); Year+1; capital+(capital.10); end; run; a. do while(Capital ge 500000); b. do while(Capital=500000); c. do while(Capital le 500000); d. do while(Capital>500000); - Answers -Correct answer: c Because the DO WHILE loop is evaluated at the top of the loop, you specify the condition that must exist in order to execute the enclosed statements 11.10 In the following program, complete the statement so that the program stops generating observations when Distance reaches 250 miles or when 10 gallons of fuel have been used. data work.go250; set cert.cars; do gallons=1 to 10 ... ; Distance=gallonsmpg; output; end; run; a. while(Distance<=250) b. when(Distance>250)

c. over(Distance le 250) d. until(Distance=250) - Answers -Correct answer: a The WHILE expression causes the DO loop to stop executing when the value of Distance becomes equal to or greater than 250 12.1 Suppose you do not specify the LIBRARY= option and your formats are stored in Work.Formats. How long do they exist? a. only for the current procedure b. only for the current DATA step c. only for the current SAS session d. permanently - Answers -Correct answer: c If you do not specify the LIBRARY= option, formats are stored in a default format catalog named Work.Formats 12.2 Which of the following statements store your formats in a permanent catalog? a. libname formtlib 'C:\Users\Student1\sas\formats\lib'; proc format lib=formtlib ...; b. libname formtlib 'C:\Users\Student1\sas\formats\lib'; format lib=formtlib ...; c. formtlib='C:\Users\Student1\sas\formats\lib'; proc format formtlib ...; d. formtlib='C:\Users\Student1\sas\formats\lib'; proc formtlib ...; - Answers -Correct answer: a To store formats in a permanent catalog, you first write a LIBNAME statement to associate the libref with the SAS data library in which the catalog will be stored 12.3 When you create a format with the VALUE statement, the new format's name cannot end with a number, cannot end with a period, and cannot be the name of a SAS format. Which of the following is also true? a. The name cannot be the name of a data set variable. b. The name must be at least two characters long. c. The name must be at least eight characters long. d. The name must begin with a dollar sign ($) if used with a character variable - Answers -Correct answer: d The name of a format that is created with a VALUE statement must begin with a dollar sign ($) if it applies to a character variable 12.4 Which of the following FORMAT procedures is written correctly? a. proc format lib=formtlib value colorfmt; 1='Red' 2='Green' 3='Blue' run; b. proc format lib=formtlib; value colorfmt