This document contains questions to test knowledge of PROC SQL and SAS Macros. The PROC SQL questions cover topics like sorting query results, joining tables, calculating averages, and creating views. The SAS Macros questions cover defining macro variables and writing a macro that counts observations in a file.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
64 views
Advanced SAS Questions
This document contains questions to test knowledge of PROC SQL and SAS Macros. The PROC SQL questions cover topics like sorting query results, joining tables, calculating averages, and creating views. The SAS Macros questions cover defining macro variables and writing a macro that counts observations in a file.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3
Advanced SAS Questions (MCQ)
Instructions: Choose the best answer for each question.
Proc SQL (5 marks) 1. Which of the following statements is used to sort the results of a PROC SQL query? a) BY (variable1, variable2); (Correct Answer) b) ORDER BY (variable1, variable2); c) SORT BY (variable1, variable2); d) RANK BY (variable1, variable2); 2. You want to select all customers from the 'customer' table who have placed an order in the 'orders' table in the last 30 days. Which of the following PROC SQL queries will achieve this? a) SELECT c.* FROM customer c, orders o WHERE c.customer_id = o.customer_id AND order_date >= DATEADD(d, - 30, GET DATE()); (Correct Answer) b) SELECT c.* FROM customer c JOIN orders o ON c.customer_id = o.customer_id WHERE order_date >= DATEADD(d, -30, GET DATE()); c) SELECT c.* FROM customer c WHERE customer_id IN (SELECT customer_id FROM orders WHERE order_date >= DATEADD(d, -30, GET DATE())); d) UPDATE customer c SET order_date = DATEADD(d, -30, GET DATE()) FROM orders o WHERE c.customer_id = o.customer_id; 3. You want to calculate the average order value for each customer in the 'customer' and 'orders' tables. Which of the following PROC SQL queries will achieve this? a) SELECT customer_id, AVG(order_amount) FROM customer c, orders o WHERE c.customer_id = o.customer_id GROUP BY customer_id; (Correct Answer) b) SELECT c.customer_id, SUM(o.order_amount) / COUNT() FROM customer c, orders o WHERE c.customer_id = o.customer_id; c) SELECT customer_id, SUM(order_amount) FROM customer c JOIN orders o ON c.customer_id = o.customer_id; d) UPDATE customer c SET avg_order_value = SUM(o.order_amount) / COUNT() FROM orders o WHERE c.customer_id = o.customer_id; 4. You have a table with product ID, product name, and price. You want to create a new variable named 'discount' that is 10% of the price. Which of the following PROC SQL queries will achieve this? a) SELECT product_id, product_name, price, price * 0.1 AS discount FROM products; (Correct Answer) b) UPDATE products SET discount = price * 0.1; c) ALTER TABLE products ADD discount = price * 0.1; d) CREATE TABLE discounted_products SELECT product_id, product_name, price, price * 0.1 AS discount FROM products; 5. Which of the following statements is used to create a temporary view in PROC SQL? a) CREATE VIEW view_name AS SELECT * FROM table_name; (Correct Answer) b) CREATE TABLE view_name AS SELECT * FROM table_name; c) DECLARE VIEW view_name AS SELECT * FROM table_name; d) TEMPORARY VIEW view_name AS SELECT * FROM table_name; SAS Macros (5 marks) 1. Which of the following statements is used to define a macro variable in SAS? a) %LET var_name = value; (Correct Answer) b) VAR var_name = value; c) DEFINE var_name = value; d) SET var_name = value; 2. You want to write a macro that takes a filename as an argument and prints the number of observations in that file. Which of the following macro code snippets will achieve this? a) %MACRO count_obs(filename); %LET num_obs = INFILE '&filename' LRECL=32767 MISSOVER; INPUT; RUN; %PUT The number of observations in &filename is %NUMOBS; %MEND count_obs; (Correct Answer) b) %MACRO count_obs(filename); %LET num_obs = PROC CONTENTS DATA=&filename; RUN; %PUT The number of observations in &filename is %NUMOBS; %MEND count_obs;