1.11k likes | 1.26k Views
Chapter 4: Creating Simple Queries. Chapter 4: Creating Simple Queries. Objectives . State the function of the Filter and Sort task and the Query Builder. Compare the functionality available in each task. Filter and Sort Task and the Query Builder.
E N D
Objectives • State the function of the Filter and Sort task and the Query Builder. • Compare the functionality available in each task.
Filter and Sort Task and the Query Builder The Filter and Sort task and the Query Builder can be used to create a new data source from one or more tables according to the criteria specified by the user.
4.01 Multiple Answer Poll • Double-click on any data source in your project. Select Filter and Sort and explore the available tabs. What functionality do you think is supported by this task? • Subsetting rows • Selecting columns • Calculating new columns • Controlling the sort order of the rows • Summarizing data • Create a SAS data set
4.01 Multiple Answer Poll – Correct Answers • Double-click on any data source in your project. Select Filter and Sort and explore the available tabs. What functionality do you think is supported by this task? • Subsetting rows • Selecting columns • Calculating new columns • Controlling the sort order of the rows • Summarizing data • Create a SAS data set
Filter and Sort Task The Filter and Sort task enables you to create a new SAS table by selecting rows, columns, and a sort sequence.
4.02 Quiz Close the Filter and Sort task and return to the data grid. Select Query Builder. What options appear to be available that are not present in the Filter and Sort task?
4.02 Quiz – Correct Answer Close the Filter and Sort task and return to the data grid. Select Query Builder. What options appear to be available that are not present in the Filter and Sort task? Possible answers: Query name, Output name, Computed Columns, Prompt Manager, Tools, Options, Add Tables, Join Tables
Query Builder The Query Builder enables you to create a new SAS table by selecting rows, columns, and a sort sequence. It also enables computing new columns, joining tables, grouping, summarizing, and modifying column attributes.
Objectives • Apply a filter in a query. • Exclude columns in a query. • Reorder rows in a query.
Business Scenario Internet Orders(Order_Type =3) Orion Star wants to analyze Internet sales since 2008. To prepare the data for input to the various analytic tasks, the company must generate a new data source from the orders table, including only those Internet orders placed on or after 01JAN2008.
Filter and Sort Task The Variables, Filter, and Sort tabs in the Filter and Sort task provide functionality to select rows and columns in a designated sort order.
Filter and Sort: Filter Simple filters can be built using variable names, operators, and data values. Select Advanced Edit…to build more complex filters.
Advanced Filter Builder The Advanced Filter Builder provides access to advanced operators and SAS functions to create more complex rules for extracting rows.
Filter and Sort: Sort and Results You can sort by multiple variables, and designate either ascending or descending sequence. You can also name the task and output table.
Query Builder • The Query Builder provides similar tabs for selecting columns, filtering rows, and sorting data. Additional functionality is available, including the following: • modifying columnproperties • grouping andsummarizing data • applying formats • selecting distinctrows • joining tables
Using Query Results in Tasks Data sources generated from queries can serve as the input data for follow-up tasks.
Exercise This exercise reinforces the concepts discussed previously.
Objectives • Define a new column of data in a query by building an expression.
Business Scenario Delivery_Date - Order_Date SUM(Total_Retail_Price, Shipping) Orion Star wants to analyze shipment methods by determining how many days elapse between each order date and delivery date. The company also wants to calculate the total amount invoiced to the customer, which is the sum of total retail price and shipping charges.
Computed Columns Select to begin creatinga new column. New summarized columns, recoded columns, or columns based on an expression can be added to a query in the Query Builder.
New Computed Column Wizard A wizard guides you through the process of creating the new column and assigning attributes such as the column name, label, and format.
Expression Editor The Expression Editor enables you to build expressions based on variables, operators, and functions.
SAS Functions A SAS function is a routine that returns a value that is determined from specified arguments. General form of a SAS function: function-name(argument1,argument2, . . .) sum(Salary,Bonus) Example:
Using SAS Functions • SAS functions can do the following: • perform arithmetic operations • compute sample statistics (for example, sum, mean, and standard deviation) • manipulate SAS dates • process character values • perform many other tasks Sample statistics functionsignore missing values.
4.03 Multiple Choice Poll Var1+Var2+Var3 • What is the result of the expression given the values of Var1, Var2, and Var3? • . (missing) • 3 • 9 • 12
4.03 Multiple Choice Poll – Correct Answer Var1+Var2+Var3 • What is the result of the expression given the values of Var1, Var2, and Var3? • . (missing) • 3 • 9 • 12
4.04 Multiple Choice Poll sum(Var1,Var2,Var3) • What is the result of the expression given the values of Var1, Var2, and Var3? • . (missing) • 3 • 9 • 12
4.04 Multiple Choice Poll – Correct Answer sum(Var1,Var2,Var3) • What is the result of the expression given the values of Var1, Var2, and Var3? • . (missing) • 3 • 9 • 12
Computed Columns Computed columns appear in the left pane and can be used in a filter, for sorting, or as an input to another computed column.
Creating a Column with an Expression Delivery_Date - Order_Date SUM(Total_Retail_Price, Shipping) This demonstration illustrates using the Computed Column wizard to define new columns based on advanced expressions.
Exercise This exercise reinforces the concepts discussed previously.
Objectives • Assign a grouping variable in a query. • Select the analysis variable and the summary statisticto compute. • Filter grouped data.
Business Scenario Orion Star wants to offer a sales promotion that highlights the most lucrative products. The company would like a list of all products with a total profit that exceeds $500.
Grouping Data The Query Builder canbe used to group and summarize data.
Grouping Data Choose a statisticfor columns to be summarized. Columns without an assignedstatistic will automaticallydefine the groups. Data can be grouped and summarized using the Select Data tab.
Grouping by Column Values The query result includes one row for every unique value of the group column(s) and a calculated statistic for the summarized column(s).