SAS Programming 2: Data Manipulation Techniques
Which of the following statements contains valid syntax? a. do 1 to 10 by 2; b. do while (Year>2025); c. do until Earnings<=100000; d. do date='01JAN2019' to '31JAN2019';
B
Which option is needed in the PROC TRANSPOSE statement to rename the _NAME_ column as shown in the output table? Input Table _NAME_ COL1 COL2 Breakfast Yogurt Pancakes Lunch Sandwich Salad Dinner Steak Lasagna Output Table Meal COL1 COL2 Breakfast Yogurt Pancakes Lunch Sandwich Salad Dinner Steak Lasagna a. _name_=Meal b. name=Meal c. prefix=Meal d. rename=Meal
B
Which output table does the following step produce? data Earnings(keep=Qtr Earned); Amount=1000; Rate=.075/4; do Qtr=1 to 4; Earned+(Amount+Earned)*Rate; end; run; a. Qtr Earned 4 77.135865784 b. Qtr Earned 5 77.135865784 c. Qtr Earned 1 18.75 2 37.8515625 3 57.311279297 4 77.135865784 d. Qtr Earned 1 18.75 2 37.8515625 3 57.311279297 4 77.135865784 5 77.135865784
B
Which output table does the following step produce? data test; bike=10; do day=1 to 7 while (bike lt 13); bike=bike+2; end; run; a. Bike Day 14 2 b. Bike Day 14 3 c. Bike Day 24 7 d. Bike Day 24 8
B
Which statement is false concerning the sum statement? a. The sum statement ignores missing values. b. The sum statement initially sets the accumulator column to missing. c. The sum statements adds a numeric value to an accumulator column. d. The sum statement automatically retains the value of the accumulating column.
B
Which statement is false? a. The DO UNTIL loop executes until a condition is true. b. The DO WHILE loop always executes at least one time. c. The DO WHILE loop checks the condition at the top of the loop. d. The DO UNTIL loop checks the condition at the bottom of the loop.
B
Which statement or statements are needed in a PROC TRANSPOSE step for the following example (wide to narrow)? Wide Table Day Breakfast Lunch Dinner Saturday Yogurt Sandwich Steak Sunday Pancakes Salad Lasagna Narrow Table _NAME_ COL1 COL2 Breakfast Yogurt Pancakes Lunch Sandwich Salad Dinner Steak Lasagna a. by Day; b. var Breakfast Lunch Dinner; c. id Day; d. id Day; var Breakfast Lunch Dinner;
B
How many rows are in the bikeinfo2 output table given the following input table and code? work.bikeinfo name bike Marco 12 Angela 10 data bikeinfo2; set bikeinfo; do month=1 to 3; do week=1 to 4; bike=bike+2; end; output; end; run; a. 2 b. 3 c. 6 d. 12 e. 24
C
How many rows are in the empsauc output table given the following input tables and code? work.empsau First Region EmpID Togar E 121150 Kylie S 121151 Birin W 121152 work.phonec EmpID Phone 121150 +61(2)5555-1795 121152 +61(2)5555-1667 121153 +61(2)5555-1348 data empsauc; merge empsau phonec; by EmpID; run; a. two b. three c. four d. five
C
How many rows are written to output based on the following statement? if find(Location, "Oahu", "i") > 0 then output; Location Honolulu, Oahu Kaanapali, Maui Hilo, Hawaii kailua, oahu LAIE, OAHU a. 0 b. 1 c. 3 d. 5
C
How many rows will be in the final table if work.airwide contains three rows? data work.airnarrow; set work.airwide; Month='Jan'; Air=Jan; output; Month='Feb'; Air=Feb; output; Month='Mar'; Air=Mar; output; keep Year Month Air; run; a. 3 b. 6 c. 9 d. 12
C
What is the correct formatted output given the following PROC FORMAT step and the input table? proc format; value $answer '1'='Yes' '2'='No' 'other'='Not Answered'; run; Code 1 2 3 a. Code Yes No b. Code Yes No Not c. Code Yes No 3 d. Code Yes No Not Answered
C
What is the value of Count at the end of the third DATA step iteration? data newnums; set nums; Count+Tens; run; work.nums Tens 10 20 . 40 a. . (missing) b. 20 c. 30 d. 70
C
Which columns are required in an input table to create a format based on numeric ranges? a. FMTNAME, START, and LABEL b. FORMAT, START, END, and NAME c. FMTNAME, START, END, and LABEL d. FORMAT, START, LAST, NAME, and TYPE
C
Which expression rounds each value of Sales to the nearest hundredth (or two decimal places)? a. round(Sales) b. round(Sales, 2) c. round(Sales, .01) d. round(Sales, dollar10.2)
C
What is the value of Location in the output table? loc1 Code Location A France loc2 Code Location A Belgium loc3 Code Location A Italy data locALL; merge loc1 loc2 loc3; by Code; run; a. Italy b. France c. Belgium d. France Belgium Italy
A
Which function could be used to remove the non-numeric symbols in Phone? Phone 202-555-0190 202.555.0110 (202)555-0133 [202]555-0128 a. COMPRESS b. COMPBL c. SCAN d. FIND
A
Which is the better description for the following table? Year Jan Feb Mar Apr May Jun Yr1956 284 277 317 313 318 374 Yr1957 315 301 356 348 355 422 Yr1958 340 318 362 348 363 435 a. wide table b. narrow table
A
Which of the following does not have proper syntax for specifying a range in the VALUE statement? a. 500>-700 b. 500-<700 c. 'A'-'C' d. 'Horse'-'Mouse'
A
Which of the following functions can convert the values of the numeric variable Level to character values? a. put(Level, 3.) b. put(3., Level) c. input(3., Level) d. input(Level, 3.)
A
Which statement contains valid syntax for the RETAIN statement? a. retain Year 2018; b. retain Year*2018; c. retain Year=2018; d. retain Year{2018};
A
Which statement is false concerning the compilation phase of the DATA step? a. Initial values are assigned to the columns. b. The program data vector (PDV) is created. c. The DATA step is checked for syntax errors. d. The descriptor portion of the output table is created.
A
Which statement is false? a. The KEEP statement names the columns to include from the input table. b. The DROP statement names the columns to exclude from the output table. c. The KEEP= option in the DATA statement names the columns to include in the output table. d. The DROP= option in the SET statement names the columns to exclude from being read into the PDV.
A
Which statement is true concerning the execution phase of the DATA step? a. Data is processed in the program data vector (PDV). b. An implied OUTPUT occurs at the top of the DATA step. c. An implied REINITIALIZE occurs at the bottom of the DATA step. d. Columns read from the input table are set to missing when SAS returns to the top of the DATA step.
A
Which statement is true given the following program? data work.student; set sashelp.class; by Name; run; a. The PDV contains a temporary variable named First.Name. b. The output table work.student contains a column named Last.Name. c. The DATA step sorts the input table by the column Name. d. An error is produced because the BY statement is not permitted in the DATA step.
A
A single DATA step can be used to merge the following three tables: dataset1 Student Test Score dataset2 Subject Test dataset3 Subject AvgScore a. True b. False
B
Functions and CALL routines both return a value that must be used in an assignment statement or expression. a. True b. False
B
How many rows and columns are in the output table ShippingZones given the following information? The input table Shipping contains 5 rows and 3 columns (Product, BoxSize, and Rate). data ShippingZones; set Shipping; Zone=1; output; Zone=2; Rate=(Rate*1.5); run; a. 5 rows and 3 columns b. 5 rows and 4 columns c. 10 rows and 3 columns d. 10 rows and 4 columns
B
How many rows are in the savings output table given the following input table and code? Note: Amount is a numeric column. pg2.savings Name Amount James 250 Linda 300 Mary 275 Robert 350 data work.savings; set pg2.savings; Savings=0; do Year=1 to 5; do qtr=1 to 4; Savings+Amount; Savings+(Savings*0.02/12); end; end; run; a. 1 b. 4 c. 5 d. 20
B
In the FORMAT procedure, you specify the name of the format and the name of the column that will use the custom format. a. True b. False
B
The DATA step debugger in SAS Enterprise Guide can be used with DATA and PROC steps. a. True b. False
B
What are the correct values for First.Name and Last.Name if the value of Name appears only once in the input table? data work.student; set sashelp.class; by Name; run; a. First.Name=0 and Last.Name=0 b. First.Name=1 and Last.Name=1 c. First.Name=1 and Last.Name=0 d. First.Name=0 and Last.Name=1
B
What are the values of C and A during the third iteration of the DATA step? work.clients Name ID Ankerton 11123 Davis 22298 Masters 33351 work.amounts Name Amt Ankerton 92 Ankerton 43 Masters 27 data client_amount; merge clients(in=C) amounts(in=A); by Name; run; a. C=0 and A=0 b. C=1 and A=0 c. C=0 and A=1 d. C=1 and A=1
B
What is the result of running the following DATA step? data work.boots; set sashelp.shoes(keep=Product Subsidiary); where Product='Boot'; NewSales=Sales*1.25; run; a. The step produces work.boots with three columns. b. The step produces work.boots with four columns. c. The step produces an error due to invalid syntax for the KEEP= option. d. The step produces an error because the Sales column is not read in from the sashelp.shoes table.
B
What is the result of the following step? work.donors1 ID Type Units 2304 O 16 1129 A 48 1129 A 50 2486 B 63 work.donors2 ID Code Units 1129 63 32 2304 61 45 1387 64 67 data combine; merge donors1 donors2; by ID; run; a. The table combine is created with four columns and five rows. b. The step fails because the BY column ID is not properly sorted. c. The step fails because Units is in both tables and not the BY column. d. The step fails because of duplicate ID values within the donors1 table.
B
When using the DATA step to go from a narrow table to a wide table, the KEEP statement is needed to hold values in the PDV across multiple iterations of the DATA step. a. True b. False
B
Which DATA step statement indicates to continue processing the last row of a BY group? a. if First.JobTitle; b. if Last.JobTitle; c. where First.JobTitle=1; d. where Last.JobTitle=1;
B
Which columns are in the final table work.boots? data work.boots(drop=Product); set sashelp.shoes(keep=Product Subsidiary Sales Inventory); where Product='Boot'; drop Sales Inventory; Total=sum(Sales,Inventory); run; a. Subsidiary b. Subsidiary and Total c. Product and Subsidiary d. Product, Subsidiary, Sales, and Inventory
B
Which of the following contains valid syntax? a. value grades 'A'='Excellent' 'B'='Good'; b. value qtrfmt 1,2,3='First' 4,5,6='Second'; c. value $grades. 'A'='Excellent' 'B'='Good'; d. value qtrfmt '1'-'3'='First' '4'-'6'='Second';
B
Which of the following contains valid syntax for the FMTSEARCH= option? a. options fmtsearch=sashelp; b. options fmtsearch=sashelp.formats; c. options fmtsearch=(sashelp sashelp.fmts); d. options fmtsearch=[sashelp.fmts sashelp];
C
Which of the following functions converts the character values of Base to numeric values? a. put(comma10.2, Base) b. put(Base, comma10.2) c. input(Base, comma10.2) d. input(comma10.2, Base)
C
Which of the following statements contains valid syntax? a. do Age=10 to 14 and while (Weight<150); b. do week=1 to 52 do until (Mileage ge 2750); c. do Increase=5 to 10 while (temperature lt 102); d. do Year=2018 to 2028 or until (Earnings<=100000);
C
Which option in the PROC FORMAT statement specifies a library to store a custom format? a. CATALOG= b. FMTLIB= c. LIBRARY= d. STORE=
C
Which option is needed in the PROC TRANSPOSE statement to rename the COL columns as shown in the output table? Input Table Meal COL1 COL2 Breakfast Yogurt Pancakes Lunch Sandwich Salad Dinner Steak Lasagna Output Table Meal Day7 Day1 Breakfast Yogurt Pancakes Lunch Sandwich Salad Dinner Steak Lasagna a. out=meals2(COL1=Day7 COL2=Day1) b. out=meals2(name=(COL1=Day7 COL2=Day1)) c. out=meals2(rename=(COL1=Day7 COL2=Day1)) d. out=meals2(prefix=(COL1=Day7 COL2=Day1))
C
Which statement best describes the rows in the output table? data bonuses; merge managers(in=M) staff(in=S); by EmpID; if M=0 and S=1; run; a. all the matching rows from both managers and staff b. only the rows from managers that have no match in staff c. only the rows from staff that have no match in managers d. all the matching and nonmatching rows from both managers and staff
C
Which statement is false concerning the TRANSPOSE procedure? a. Columns are transposed into rows. b. By default, numeric columns are transposed. c. Use a BY statement to sort the data while transposing. d. Use a VAR statement to specify the character and numeric columns to transpose.
C
Which statement is not a compile-time-only statement? a. KEEP b. LENGTH c. SET d. WHERE
C
Which statement is true regarding the iterative DO loop? DO index-column = start TO stop <BY increment>; a. The start and stop values can be character or numeric values. b. If an increment value is not specified, the default increment is 0. c. The index column is incremented at the bottom of each DO loop. d. The index column is not in the final table unless specifically kept.
C
Which statement needs to be added to the DATA step to include only the last row per value of Year in the output table? data work.airwide2(keep=Year Jan Feb Mar); set work.airnarrow; by Year; retain Jan Feb Mar; if Month='Jan' then Jan=Air; else if Month='Feb' then Feb=Air; else if Month='Mar' then Mar=Air; ... insert statement here ... run; a. output; b. if Last then output; c. if Last.Year=1 then output; d. if Last.Year=0 then output;
C
Which statement reads CityCountry and correctly assigns a value to Country? CityCountry Country Athens, Greece Greece New Delhi, India India Auckland, New Zealand New Zealand a. Country=scan(CityCountry, 2); b. Country=scan(CityCountry, -1); c. Country=scan(CityCountry, 2, ','); d. Country=scan(CityCountry, 2, ', ');
C
Which statement renames the existing column Location in work.travel as Destination? a. set vacations(rename=(Location=Destination)) travel; b. set vacations travel(rename=(Destination=Location)); c. set vacations travel(rename=(Location=Destination)); d. set vacations travel(rename(Destination=Location));
C
Which step executes successfully without an error, given the input table sashelp.class? Name Sex Age Height Weight Alfred M 14 69 112.5 Alice F 13 56.6 84 a. data new; set sashelp.class; Ratio=Height/Weight; where Sex='M' & Ratio>0.6; run; b. data new; set sashelp.class; where Sex='M'; Ratio=Height/Weight; where Ratio>0.6; run; c. data new; set sashelp.class; where Sex='M'; Ratio=Height/Weight; if Ratio>0.6; run; d. data new; set sashelp.class; if Sex='M'; Ratio=Height/Weight; where Ratio>0.6; run;
C
How many rows are in the both output table given the following input tables and code? work.agetable Name Age Bob 12 Sue 15 work.foodtable Name Food Bob Pizza Bob Cupcakes Sue Burgers Sue Grapes Sue Brownies data both; merge agetable foodtable; by Name; run; a. two b. three c. four d. five
D
The sashelp.cars table contains 428 rows: 123 rows with Origin equal to Europe and 305 rows with Origin equal to other values. data Europe Other; set sashelp.cars; if Origin='Europe' then output Europe; output Other; run; How many rows will be in the Other table? a. 0 rows b. 123 rows c. 305 rows d. 428 rows
D
What are the values for First.City and Last.City for the THIRD row of the input table given the following information? data StatePopulation; set Population; by State City; run; State City Population NC Cary 162320 NC Durham 263016 NC Greenville 91495 SC Greenville 67453 SC Sumter 40723 a. First.City=0 and Last.City=0 b. First.City=1 and Last.City=0 c. First.City=0 and Last.City=1 d. First.City=1 and Last.City=1
D
What is the default search order that is used to locate formats? a. LIBRARY.FORMATS > WORK.FORMATS b. SASHELP.FORMATS > LIBRARY.FORMATS c. SASHELP.FORMATS > WORK.FORMATS d. WORK.FORMATS > LIBRARY.FORMATS
D
What is the final value of Year given the following step? data invest; do Year=2010 to 2019; Capital+5000; Capital+(Capital*.03); end; run; a. . (missing) b. 2010 c. 2019 d. 2020
D
What is the formatted value for the value of 100 given the following step? proc format; value rates 1-<100='low' 100<-<200='medium' 200-300 ='high' other ='out of range'; run; a. low b. medium c. high d. out of range
D
What is the value of Count at the end of the third DATA step iteration? data newnums; set nums; retain Count 100; Count+Tens; run; work.nums Tens 10 20 30 40 a. . (missing) b. 60 c. 130 d. 160
D
What is the value of x at the completion of the DATA step? data test; x=15; do until(x>12); x+1; end; run; a. . (missing) b. 13 c. 15 d. 16
D
When using the DATA step to go from a wide tabe to a narrow table, which statement is needed for creating multiple rows from a single row? a. WIDE b. NARROW c. RETAIN d. OUTPUT
D
Which PUTLOG statements create the following results in the SAS log? Name=Alfred Height=69 Weight=112.5 Ratio=0.61 _ERROR_=0 _N_=1 Ratio=0.61 a. putlog all; putlog Ratio; b. putlog all; putlog Ratio=; c. putlog _all_; putlog Ratio; d. putlog _all_; putlog Ratio=;
D
Which expression creates CityCountry? City Country CityCountry Athens Greece Athens, Greece New Delhi India New Delhi, India Auckland New Zealand Auckland, New Zealand a. cat(City, ", ", Country) b. cats(", ", City, Country) c. catx(City, ", ", Country) d. catx(", ", City, Country)
D
Which function calculates the average of the columns Week1, Week2, Week3, and Week4? a. mean(Week1, Week4) b. mean(Week1-Week4) c. mean(of Week1, Week4) d. mean(of Week1-Week4)
D
Which statement is true concerning concatenating tables? a. All tables must have the same number of columns. b. Columns in all tables must have matching names and lengths. c. Tables must be in the same library. d. Missing values are generated for columns that exist in one input table and not in another.
D
Which statement is true concerning merging with matching rows? a. The MERGE statement must refer to temporary input tables. b. The columns in the BY statement can be in only one of the tables. c. Only two input tables can be specified in the MERGE statement. d. The input tables must be sorted by the columns in the BY statement.
D
Which statement is true concerning options for the FORMAT procedure? a. The FMTLIB option goes in the SELECT statement. b. The CNTLIN= option goes in the VALUE statement. c. The FMTLIB option specifies the library to store the format. d. The CNTLIN= option specifies a table from which formats are built.
D
Which statement needs to be added to the DATA step to reset the value of Total for each new BY group? data RegionTotal; set Sales; by Region; ... add statement here ... Total+Sales; if Last.Region=1 then output; run; a. Total=0; b. if Last.Region=0 then Total=0; c. if First.Region=0 then Total=0; d. if First.Region=1 then Total=0;
D
Which statements are needed in a PROC TRANSPOSE step for the following example (narrow to wide)? Narrow Table Day Meal Food Saturday Breakfast Yogurt Saturday Lunch Sandwich Saturday Dinner Steak Sunday Breakfast Pancakes Sunday Lunch Salad Sunday Dinner Lasagna Wide Table Day Breakfast Lunch Dinner Saturday Yogurt Sandwich Steak Sunday Pancakes Salad Lasagna a. by Day; var Meal Food; b. id Day; var Food Meal; c. by Day; id Food; var Meal; d. by Day; id Meal; var Food;
D
Which step is not required when converting a character column named Date to a numeric SAS date column with the same name? a. Rename the Date column to a new name, such as CharDate. b. Use the INPUT function to read the renamed CharDate character column and create a numeric column named Date. c. Specify an appropriate informat in the INPUT function. d. Format the new numeric Date column.
D