Оцените презентацию от 1 до 5 баллов!
Тип файла:
ppt / pptx (powerpoint)
Всего слайдов:
29 слайдов
Для класса:
1,2,3,4,5,6,7,8,9,10,11
Размер файла:
262.50 kB
Просмотров:
71
Скачиваний:
0
Автор:
неизвестен
Слайды и текст к этой презентации:
№1 слайд![SQL Chapter Two](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img0.jpg)
Содержание слайда: SQL Chapter Two
№2 слайд![Overview Basic Structure](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img1.jpg)
Содержание слайда: Overview
Basic Structure
Verifying Statements
Specifying Columns
Specifying Rows
№3 слайд![Introduction SQL is a modular](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img2.jpg)
Содержание слайда: Introduction
SQL is a modular language that uses statements and clauses.
№4 слайд![Basic structure of PROC SQL](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img3.jpg)
Содержание слайда: Basic structure of PROC SQL:
PROC SQL;
statement (select)
clauses (from, where, group by, having, order by);
QUIT;
Note: place semicolon at the end of the last clause only.
№5 слайд![Statements select - specifies](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img4.jpg)
Содержание слайда: Statements
select - specifies the columns to be selected
Select statement has the following features:
-selects data that meets certain conditions
-groups data
-specifies an order for the data
-formats data
-calculates new variables
№6 слайд![Clauses from - specifies the](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img5.jpg)
Содержание слайда: Clauses
from - specifies the tables to be queried
where - subsets the data based on a condition - optional
group by - classifies the data into groups - optional
having - subsets groups of data based on a group condition
order by - sorts row by the values of specific columns
Note: the order of the clauses are significant.
№7 слайд![Overview Basic Structure](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img6.jpg)
Содержание слайда: Overview
Basic Structure
Verifying Statements
Specifying Columns
Specifying Rows
№8 слайд![Verifying Statements Two](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img7.jpg)
Содержание слайда: Verifying Statements
Two functions that can be used to verify if your statement syntax are:
validate - used to check the select statement syntax
noexec - checks for invalid syntax in all types of SQL statements
№9 слайд![Validate proc sql validate](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img8.jpg)
Содержание слайда: Validate
proc sql;
validate
select timemile, restpulse, maxpulse
from project.fitness
where timemile gt 7;
NOTE: PROC SQL statement has valid syntax.
№10 слайд![NoExect proc sql noexec](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img9.jpg)
Содержание слайда: NoExect
proc sql noexec;
select timemile, restpulse, maxpulse
from project.fitness
where timemile gt 7;
NOTE: Statement not executed due to NOEXEC option.
№11 слайд![Contrasting Features of](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img10.jpg)
Содержание слайда: Contrasting
Features of validate:
-tests syntax of query without executing the query
-checks the validity of column name
-prints error messages for invalid queries
-is only used for select statements
№12 слайд![Overview Basic Structure](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img11.jpg)
Содержание слайда: Overview
Basic Structure
Verifying Statements
Specifying Columns
Specifying Rows
№13 слайд![Specifying Columns Objectives](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img12.jpg)
Содержание слайда: Specifying Columns
Objectives
-Displaying columns directly from a table
-Displaying columns calculated from other columns
-Calculating columns using a CASE expression
№14 слайд![Displaying data from a table](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img13.jpg)
Содержание слайда: Displaying data from a table
To print all of a table columns in the order that they were stored, use an asterisk in the SELECT statement:
PROC SQL;
SELECT *
FROM VITALS;
QUIT;
№15 слайд![Printing Specify Columns If](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img14.jpg)
Содержание слайда: Printing Specify Columns
If you do not want to print out all columns in a table in the order that they were stored, you can specify the columns to be printed in the order that you want them in the SELECT statement or CASE EXPRESSION in the select statement .
PROC SQL;
CREATE TABLE TESTMED AS
SELECT PATIENT,
CASE ((PATIENT/2 = INT(PATIENT/2)) +
(PATIENT = .))
WHEN 1 THEN 'Med A'
WHEN 0 THEN 'Med B'
ELSE 'Error'
END AS DOSEGRP
LENGTH=5
FROM VITALS
ORDER BY PATIENT;
QUIT;
№16 слайд![Calculating Columns We can](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img15.jpg)
Содержание слайда: Calculating Columns
We can calculate a new column by using data in an existing column and then naming the new column using the as function.
Calculate the proportion of Units form each country
CODE:
№17 слайд![Calculated columns using SAS](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img16.jpg)
Содержание слайда: Calculated columns using SAS Dates
Recall from previous chapters in our SAS book that dates are stored in a different format when run through SAS.
We will then use these dates to calculate new columns.
№18 слайд![Example Calculate the range](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img17.jpg)
Содержание слайда: Example: Calculate the range of dates in a Dailyprices dataset.
CODE:
№19 слайд![Creating new columns The use](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img18.jpg)
Содержание слайда: Creating new columns
The use of CASE expression can be used to create a new column
CODE:
№20 слайд![Creating a table To create](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img19.jpg)
Содержание слайда: Creating a table
To create and populate a table with the rows from an SQL query, use create table.
proc sql;
create table states as
select state_code, state_name
from d2data.state;
quit;
№21 слайд![Overview Basic Structure](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img20.jpg)
Содержание слайда: Overview
Basic Structure
Verifying Statements
Specifying Columns
Specifying Rows
№22 слайд![Specifying Rows in a table](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img21.jpg)
Содержание слайда: Specifying Rows in a table
Objectives
-Selecting a subset of rows
-Removing duplicate rows
-Subsetting using where clauses, escape clauses, and calculated values
№23 слайд![Selecting a subset of rows](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img22.jpg)
Содержание слайда: Selecting a subset of rows
proc sql;
title 'large orders';
select Product_ID, total_retail_price
from d2data.order_item
where total_retail_price > 1000;
quit;
№24 слайд![Where clause Use a where to](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img23.jpg)
Содержание слайда: Where clause
Use a where to specify a condition that data must fulfill before being selected.
CODE:
OUTPUT:
Where clauses uses common comparisons (lt, gt, eq, etc) and logical operators (OR, Not, And, In, Is Null, ...).
№25 слайд![Removing duplications Use](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img24.jpg)
Содержание слайда: Removing duplications
Use distinct keyword to eliminate duplications.
CODE (without DISTINCT): CODE (with DISTINCT):
OUTPUT:
№26 слайд![Escape Clause The escape](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img25.jpg)
Содержание слайда: Escape Clause
The escape clause allows you to designate a single character that will indicate how proc sql will interpret LIKE wildcards when SAS is searching within a character string.
CODE:
№27 слайд![Subsetting calculated values](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img26.jpg)
Содержание слайда: Subsetting calculated values
Since the where clause is evaluated before the select, it's possible for an error to show up since the columns used in the where clause must exist in the table or be derived from an existing column.
There are two fixes for this, the first would be repeating the calculation in the where clause. The alternative method would be using CALCULATED keyword to refer to an already calculated column in the select.
№28 слайд![Subsetting calculated values](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img27.jpg)
Содержание слайда: Subsetting calculated values
proc sql;
title 'Lack of profit';
select Product_ID,
((total_retail_price/quantity) - costprice_per_Unit) as profit
from d2data.order_item
where calculated profit < 3;
quit;
title;
№29 слайд![Summary Basic Structure PROC](/documents_6/e69c96bc84f067ca2da09e2996a2441b/img28.jpg)
Содержание слайда: Summary
Basic Structure
PROC SQL;
statement (select)
clauses (from, where, group by, having, order by);
QUIT;
Verifying Statements
validate - used to check the select statement syntax
noexec - checks for invalid syntax in all types of SQL statements
Specifying Columns
Displaying columns directly from a table
Displaying columns calculated from other columns
Calculating columns using a CASE expression
Specifying Rows
Selecting a subset of rows
Removing duplicate rows
Subsetting using where clauses, escape clauses, and calculated values