Advanced Subqueries In PROC SQL
|
|
|
- Lynne Miles
- 10 years ago
- Views:
Transcription
1 Advanced Subqueries In PROC SQL PROC SQL; SELECT STATE, AVG(SALES) AS AVGSALES FROM USSALES GROUP BY STATE HAVING AVG(SALES) > (SELECT AVG(SALES) FROM USSALES); QUIT; STATE AVGSALES IL MI Steve First 2997 Yarmouth Greenway Drive, Madison, WI Phone: (608) Web: 1
2 Advanced Subqueries In PROC SQL This paper was written by Systems Seminar Consultants, Inc. SSC specializes in SAS software and offers: SAS Training Services Consulting Services SAS Support Plans Newsletter Subscriptions to The Missing Semicolon COPYRIGHT 2009 Systems Seminar Consultants, Inc. All rights reserved. Printed in the United States of America. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, or otherwise, without prior written permission of SSC. SAS is a registered trademark of SAS Institute Inc. in the USA and other countries. The Missing Semicolon is a trademark of Systems Seminar Consultants, Inc. 2
3 Review of PROC SQL Basics Introduction / Features The SELECT Statement Writing reports using SQL Creating a SAS dataset Joining Tables 3
4 Terminology The terminology in SQL is slightly different than in standard SAS, but the meaning is the same. SAS SQL dataset = table variable = column observation = row Name Division Years Sales Expense State 1 CHRIS H WI 2 MARK H WI 3 SARAH S MN 4 PAT H IL 5 JOHN H WI 6 WILLIAM H MN 7 ANDREW S MN 8 BENJAMIN S IL 4
5 What Does SQL Mean? Structured Query Language SQL is a standardized, widely used language. SQL is often pronounced sequel 5
6 What is SQL? Origins Authored by Dr. E.F. Codd of IBM ANSI Standards 1986, 1989, 1992, 1999, 2003 DDL (data definition language) and DML (data manipulation language). We are concentrating on DML. Simple Syntax - Easy to understand data flow (multiple tables in, one table out) - Small number of verbs (clauses) Standardize Your Data Preparation in SAS: Use SQL! 6
7 What Are The Features of PROC SQL? A base SAS Procedure Combines DATA and PROC step capabilities Similar to ANSI standard SQL syntax Can read SAS Data Files, Views, data bases (with SAS/ACCESS) Can build SAS Data Files and Views, data bases (with SAS/ACCESS) May be more efficient than standard SAS code 7
8 A Sample of PROC SQL Syntax PROC SQL; SELECT STATE, SALES, (SALES *.05) AS TAX FROM USSALES; QUIT; Notes: Multiple columns are separated by commas The SELECT statement DOES NOT limit the number of columns processed (all are read in) At least one SELECT statement required The select statement names the columns and defines the order in which they will appear The SELECT statement can dynamically create new columns 8
9 Resulting Query (Output Window) STATE SALES TAX ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ WI WI WI MI MI IL IL IL IL
10 The SELECT Statement's Syntax PROC SQL options; SELECT column(s) FROM table-name view-name WHERE expression GROUP BY column(s) HAVING expression ORDER BY column(s) ; QUIT; WOW! Only ONE Semi-Colon!! Notes: The SELECT statement describes the appearance of the query It contains several clauses The sequence of the clauses is important 10
11 The SELECT Clause PROC SQL options; SELECT column(s) FROM table-name view-name WHERE expression GROUP BY column(s) HAVING expression ORDER BY column(s) ; Select columns or create new ones QUIT; Notes: QUIT not required, can have more SELECT statements 11
12 The FROM Clause PROC SQL options; SELECT column(s) FROM table-name view-name WHERE expression GROUP BY column(s) HAVING expression ORDER BY column(s) ; Name the input source Notes: The FROM table name can be a SAS data set, a view, or a DBMS table (such as Oracle or DB2) 12
13 The WHERE Clause PROC SQL options; SELECT column(s) FROM table-name view-name WHERE expression GROUP BY column(s) HAVING expression ORDER BY column(s) ; Sub-set rows from the table Notes: The WHERE clause subsets rows from the in-coming table 13
14 The GROUP BY Clause PROC SQL options; SELECT column(s) FROM table-name view-name WHERE expression GROUP BY column(s) HAVING expression ORDER BY column(s) ; Group rows for summarization Notes: The GROUP BY clause specifies how to group the data for summarizing Similar to the CLASS statement in PROC MEANS or SUMMARY 14
15 The HAVING Clause PROC SQL options; SELECT column(s) FROM table-name view-name WHERE expression GROUP BY column(s) HAVING expression ORDER BY column(s) ; Subset the GROUP BY results Notes: The HAVING clause subsets results of the GROUP BY clause (summary level) 15
16 The ORDER BY Clause PROC SQL options; SELECT column(s) FROM table-name view-name WHERE expression GROUP BY column(s) HAVING expression ORDER BY column(s) ; Order (sort) the resulting rows Notes: PROC SORT is NOT required, SQL will sort when doing the query 16
17 Placement of the SELECT Clauses Matters... SELECT FROM WHERE GROUP BY HAVING ORDER BY Acronym anyone? SOME FRENCH WAITERS GROW HAIRY (HEALTHY?) ORANGES 17
18 Several SELECT clauses at once proc sql; SELECT state, sum(sales) as totsales FROM ussales WHERE state in ('WI','MI, IL ) GROUP BY state HAVING sum(sales) > ORDER BY state desc ; quit; STATE totsales ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ MI IL Notes: Column alias (i.e. column heading, new variable) defined by AS keyword WI not in report since the sum(sales) was under 40,000 18
19 Creating New Columns proc sql double; SELECT substr(storeno,1,2) as region sum(sales) FROM ussales GROUP BY region; quit; label='region of Store', format=dollar12. SAS Enhancements to ANSI Standard SQL : DATA step functions can be used in an expression to create a new column except LAG(), DIF(), and SOUNDEX() Labels, formats, and widths can be assigned as column modifiers Options on the Proc SQL Statement 19
20 SELECT Clause INTO Create Macro Variables The SELECT clause can also be used to: Create Macro Variables Example: * USE PROC SQL TO BUILD MACRO VARIABLE; * THE 'INTO :MACRO-VARIABLE-NAME' BUILDS THE; * MACRO VARIABLE FROM RETURNED ROWS; PROC SQL; SELECT CODE INTO :MINCODES SEPARATED BY ',' FROM CODES; RUN; %PUT MACRO VARIABLE 'MINCODES' = &MINCODES; SAS LOG: 335 %PUT MACRO VARIABLE 'MINCODES' = &MINCODES; SYMBOLGEN: Macro variable MINCODES resolves to 123,456,789 MACRO VARIABLE 'MINCODES' = 123,456,789 20
21 SELECT Clause INTO Use Macro Variable Use the Macro Variable in a WHERE statement. Example: * COULD USE IN PROC PRINT; PROC PRINT DATA=NAMES; WHERE NUMBER IN (&MINCODES); RUN; Obs NUMBER NAME DAVE MARY LINDA * COULD ALSO USE IN SQL QUERY; PROC SQL; SELECT * FROM NAMES WHERE NUMBER IN (&MINCODES); QUIT; NUMBER NAME ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 123 DAVE 456 MARY 789 LINDA 21
22 Enhancing the Appearance of Reports TITLE 'REPORT OF THE U.S. SALES'; FOOTNOTE 'PREPARED BY THE MARKETING DEPT.'; OPTIONS LS=64 PS=16 NOCENTER; PROC SQL; SELECT STATE, SALES FORMAT=DOLLAR10.2 LABEL='AMOUNT OF SALES', (SALES *.05) AS TAX FORMAT=DOLLAR7.2 LABEL='5% TAX' FROM USSALES; QUIT; Notes: Titles, Footnotes, Global Options, Formats, and Labels work like in other SAS steps 22
23 The Resulting Output REPORT OF THE U.S. SALES AMOUNT OF STATE SALES 5% TAX WI $10, $ WI $9, $ WI $15, $ MI $33, PREPARED BY THE MARKETING DEPT. 23
24 The CASE Expression (New Column) PROC SQL; SELECT STATE, CASE WHEN SALES<10000 THEN 'LOW' WHEN SALES<15000 THEN 'AVG' WHEN SALES<20000 THEN 'HIGH' ELSE 'VERY HIGH' END AS SALESCAT FROM USSALES; QUIT; Notes: END is required when using the CASE WHENs in descending probability improve efficiency With no ELSE condition, missing values result 24
25 The Resulting Output STATE SALESCAT ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ WI AVG WI LOW WI HIGH MI VERY HIGH MI VERY HIGH IL VERY HIGH IL AVG IL VERY HIGH IL VERY HIGH 25
26 Variation on the CASE PROC SQL; SELECT STATE, CASE WHEN SALES <= THEN 'LOW' WHEN <= SALES <= THEN 'AVG' WHEN <= SALES <= THEN 'HIGH' ELSE 'VERY HIGH' END AS SALESCAT FROM USSALES; QUIT; Notes: Output is the same as previous output 26
27 GROUP BY Summarization PROC SQL; SELECT STATE, SUM(SALES) AS TOTSALES FROM USSALES GROUP BY STATE; QUIT; STATE TOTSALES IL MI WI Notes: GROUP BY summarizes Use summary functions on the numeric columns for statistics Other summary functions: AVG/MEAN, MAX, MIN, COUNT/FREQ/N, NMISS, STD, SUM, and VAR 27
28 Subsetting Using the WHERE Clause Select only specified rows for the output. Character SELECT * FROM USSALES WHERE STATE IN ('OH','IN','IL'); Numeric Compound SELECT * FROM USSALES WHERE STATE IN ('OH','IN','IL') AND SALES > 500; SELECT * FROM USSALES WHERE NSTATE IN (10, 20,30); 28
29 WHERE with GROUP BY (error) PROC SQL; SELECT STATE, STORENO, SUM(SALES) AS TOTSALES FROM USSALES GROUP BY STATE, STORENO WHERE TOTSALES > 500; QUIT; Notes: WHERE cannot be used with summary variables when using the GROUP BY. (see next slide for resulting log) 29
30 The Resulting Log 94 PROC SQL; 95 SELECT STATE, STORENO,SUM(SALES) AS TOTSALES 96 FROM USSALES 97 GROUP BY STATE 98 WHERE TOTSALES > 500; ERROR : Expecting one of the following: (, **, *, /, +, -,!!,, <, <=, <>, =, >, >=, EQ, GE, GT, LE, LT, NE, ^=, ~=, &, AND,!, OR,, ',', HAVING, ORDER. The statement is being ignored. ERROR : The option or parameter is not recognized. 99 QUIT; NOTE: The SAS System stopped processing this step because of errors. NOTE: The PROCEDURE SQL used 0.05 seconds. 30
31 Fix by Using the HAVING Clause PROC SQL; SELECT STATE, STORENO, SUM(SALES) AS TOTSALES FROM USSALES GROUP BY STATE, STORENO HAVING SUM(SALES) > 500; QUIT; STATE STORENO TOTSALES IL IL IL IL MI Notes: To subset data when grouping is in effect, HAVING must be used 31
32 Checking for Duplicates PROC SQL; SELECT CUSTID FROM CONTACTS GROUP BY CUSTID HAVING COUNT(*) > 1; QUIT; Notes: Duplicate Customers CUSTID ƒƒƒƒƒƒ Summary function does not need to be on the select statement. 32
33 Creating Tables PROC SQL; CREATE TABLE SUMSALE AS SELECT STATE, SUM(SALES) AS TOTSALES FROM USSALES GROUP BY STATE; QUIT; PROC PRINT DATA=SUMSALE; RUN; Create table will create SAS dataset Obs STATE TOTSALES 1 IL MI WI Notes: When a CREATE statement is used in conjunction with a SELECT statement, a report will not be generated. 33
34 Creating Tables - SAS LOG 118 PROC SQL; 119 CREATE TABLE SUMSALE AS 120 SELECT STATE, 121 SUM(SALES) AS TOTSALES 122 FROM USSALES 123 GROUP BY STATE; NOTE: Table WORK.SUMSALE created, with 3 rows and 2 columns. 124 QUIT; NOTE: PROCEDURE SQL used: real time cpu time 0.13 seconds 0.00 seconds PROC PRINT DATA=SUMSALE; 127 RUN; NOTE: There were 3 observations read from the data set WORK.SUMSALE. NOTE: PROCEDURE PRINT used: real time cpu time 0.10 seconds 0.00 seconds 34
35 Joining Data In SQL Some of the different types of joins in PROC SQL: Cartesian Join Inner Join Outer Join Left Join Right Join Full Join Notes: Data need not be pre-sorted before joining Up to 32 tables can be joined in one query (16 pre-v8) 35
36 What is a Subquery? A subquery (inner query) is a query-expression that is nested as part of another query-expression. Subqueries are coded within parentheses. Results of the subquery are to be used as value(s) within the outer select. Subqueries, also known as inner queries, are evaluated before the outer query. Subqueries can reference the same data set as the outer query. Depending on the clause that contains it, a subquery can return a single value or multiple values. Subqueries are usually used with WHERE and HAVING expressions. Subqueries can also be used as part of the FROM and SELECT expressions Subqueries can be nested several levels deep. 36
37 Single-Value Subqueries Returns a single row and column. Can be used in a WHERE or HAVING clause with a comparison operator. It must return only one value or the query fails. Which states have average sales greater than the company's average sales? PROC SQL; SELECT STATE, AVG(SALES) AS AVGSALES FROM USSALES GROUP BY STATE HAVING AVG(SALES) > (SELECT AVG(SALES) FROM USSALES) ; QUIT; 37
38 Single-Value Subqueries The subquery is evaluated first and returns the overall average ( ) to the outer query. The effective outer query is: PROC SQL; SELECT STATE, AVG(SALES) AS AVGSALES FROM USSALES GROUP BY STATE HAVING AVG(SALES) > ; QUIT; STATE AVGSALES IL MI
39 Multiple-Value Subqueries Returns more than one value from one column. Are used in HAVING or WHERE expression that contains IN operator or that is modified by ANY or ALL. 39
40 Evaluating More Than One Row (Error) More than one row cannot be returned without additional options. PROC SQL; QUIT; SELECT STATE, STORENO, SALES FROM FEBSALES WHERE STATE IN ('WI','IL') AND SALES < (SELECT SALES FROM JANSALES) ; The resulting log (partial): 550 PROC SQL; 551 SELECT STATE, STORENO, SALES 552 FROM FEBSALES 553 WHERE STATE IN ('WI','IL') AND SALES < 554 (SELECT SALES 555 FROM JANSALES); ERROR: Subquery evaluated to more than one row. NOTE: The SAS System stopped processing this step because of errors. 40
41 The ALL Keyword Subquery Option The comparison is true for all values returned on the subquery. PROC SQL; SELECT STATE, STORENO, SALES FROM FEBSALES WHERE STATE IN ('WI','IL') AND SALES < ALL (SELECT SALES FROM JANSALES) ; QUIT; The resulting output: STATE STORENO SALES WI IL Notes; This selects rows where SALES from FEBSALES is less than ALL the values from JANSALES or, in effect, less than the minimum value found in JANSALES. 41
42 Another Way to Select Rows Less Than Minimum A subquery using MIN returns the same results. PROC SQL; QUIT; SELECT STATE, STORENO, SALES FROM FEBSALES WHERE STATE IN ('WI','IL') AND SALES < The resulting output: STATE STORENO SALES WI IL (SELECT MIN(SALES) FROM JANSALES) ; 42
43 The ANY Keyword Subquery Option The comparison is true for any one of the values returned on the subquery. PROC SQL; SELECT STATE, SALES FROM FEBSALES WHERE STATE IN ('WI','IL') AND SALES < ANY QUIT; (SELECT SALES FROM JANSALES) ; The resulting output: STATE SALES WI WI WI WI IL IL IL IL
44 The ANY Keyword Subquery Option (continued) Notes: This selects rows where sales from FEBSALES is less than ANY of the JANSALES values or, in effect, less than the maximum value found on JANSALES. 44
45 Another Way to Select Less Than Maximum The MAX function acts like the ANY option.. PROC SQL; QUIT; SELECT STATE, SALES FROM FEBSALES WHERE STATE IN ('WI','IL') AND SALES < The resulting output: (SELECT MAX(SALES) FROM JANSALES) ; STATE SALES WI WI WI WI IL IL IL IL
46 The IN Condition IN compares each outer row to the list of values returned by the subquery. COMPRESS and concatenation can be used to construct a unique key. Example: Who are the employees and which stores do they work for that have had an insurance claim? PROC SQL; SELECT FNAME, LNAME, STORENO FROM EMPLOYEE WHERE COMPRESS(FNAME!! LNAME) IN (SELECT COMPRESS(FNAME!! LNAME) FROM BENEFITS) ; QUIT; 46
47 The IN Condition (continued) The resulting output: ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ ANN BECKER CHRIS DOBSON ALLEN PARK BETTY JOHNSON
48 The NOT IN Condition Who are the employees and which stores do they work for that have not had an insurance claim? PROC SQL; SELECT FNAME, LNAME, STORENO FROM EMPLOYEE WHERE COMPRESS(FNAME!! LNAME) NOT IN (SELECT COMPRESS(FNAME!! LNAME) FROM BENEFITS) ; QUIT; 48
49 The NOT IN Condition (continued) The resulting output: FNAME LNAME STORENO EARL FISHER GARY HOWE JACK KELLER LARRY MOORE NANCY PAUL RICK TENNY VIC WATSON ARNIE CARLSON DAVID GELDER HARRY JACKSON KELLY LARSON MARY NELSON PAULA RILEY
50 Checking Multiple Valaues in the Subquery Select employees that had a claim over PROC SQL; SELECT * FROM EMPLOYEE WHERE COMPRESS(LNAME!! FNAME) IN QUIT; The resulting output: (SELECT COMPRESS(LNAME!! FNAME) FROM BENEFITS WHERE CLAIMS > 1000) ; FNAME LNAME STORENO ANN BECKER ALLEN PARK BETTY JOHNSON
51 Correlated Subqueries The previous subqueries have been simple subqueries that are selfcontained and that execute independently of the outer query. A correlated subquery requires a value or values to be passed to it by the outer query. After the subquery runs, it passes the results back to the outer query. Correlated subqueries can return single or multiple values. Source: PROC SQL documentation. 51
52 Correlated Subquery Example proc sql; title 'Oil Reserves of Countries in Africa ; select * from sql.oilrsrvs o where 'Africa' = (select Continent from sql.countries c where c.name = o.country); Quit; Processing: The outer query selects the first row from the OILRSRVS table and then passes the value of the Country column, Algeria, to the subquery. At this point, the subquery internally looks like this: (select Continent from sql.countries c where c.name = 'Algeria'); The subquery selects that country from the COUNTRIES table. Subquery then passes the country's continent back to the WHERE clause in the outer query. If the continent is Africa, then the country is selected and displayed. The outer query then selects each subsequent row from the OILRSRVS table and passes the individual values of Country to the subquery. The subquery returns the appropriate values of Continent to the outer query for comparison in its WHERE clause. 52
53 Correlated Subquery Output Oil Reserves of Countries in Africa Country Barrels Algeria 9,200,000,000 Egypt 4,000,000,000 Gabon 1,000,000,000 Libya 30,000,000,000 Nigeria 16,000,000,000 53
54 Subqueries on Multiple Tables Select customers with no purchase in last six months. PROC SQL; CREATE TABLE Nopurch_last180_w as SELECT * FROM Customers WHERE Custid NOT IN (SELECT Custid FROM Orders WHERE Today() - Odate le 180 ) ; Quit; Proc Print Data=Nopurch_last180_w; Run; Obs State Countrycode Custid 1 WI US
55 Subqueries Against Different Data Sets Select store names, state that had over $20,000 sales in February? PROC SQL; SELECT STATE, STORENAM, STORENO FROM USSALES WHERE STORENO IN (SELECT STORENO FROM FEBSALES WHERE SALES > 20000) ; QUIT; STATE STORENAM STORENO MI WOODBRIDGE GROCERS IL OAKRIDGE GROCERY STORE IL VICTOR'S FOOD CENTRE IL SAVE U MONEY A subquery can only contain one variable on the SELECT statement. 55
56 The PROC SQL PASS-Through Facility FROM subqueries are Passed Through to the DBMS on the FROM expression. The results set is processed by SAS in the outer query. Example: Go to Teradata and pull party_id and total paid by that party. PROC SQL INOBS=100; CONNECT TO TERADATA(USER=userid PASSWORD=password TDPID=DTDATA1A); SELECT PARTY_ID, TOTPAID FROM CONNECTION TO TERADATA (SELECT PARTY_ID, SUM(TOTALPAID_AMT) AS TOTPAID FROM CUSTOMER_SUMMARY GROUP BY PARTY_ID FROM CUSTOMER_SUMMARY); QUIT; 56
57 The PROC SQL PASS-Through Facility List PARTY_ID, TOT_PAID for customers with TOTALPAID_AMT less than average TOTALPAID_AMT of all customers. PROC SQL INOBS=100; CONNECT TO TERADATA(USER=userid PASSWORD=password TDPID=DTDATA1A); SELECT PARTY_ID, TOTPAID FROM CONNECTION TO TERADATA (SELECT PARTY_ID, SUM(TOTALPAID_AMT) AS TOTPAID FROM CUSTOMER_SUMMARY GROUP BY PARTY_ID HAVING SUM(TOTALPAID_AMT) < (SELECT AVG(TOTALPAID_AMT) FROM CUSTOMER_SUMMARY)); QUIT; Note: One subquery is nested in another. 57
58 The PROC SQL PASS-Through Facility List FIRST_NAME, LAST_NAME from INDIVIDUAL table all customers with TOTALPAID_AMT > $90 in CUSTOMER_SUMMARY table. PARTY_ID is the common key between these two tables. PROC SQL INOBS=100; CONNECT TO TERADATA(USER=userid PASSWORD=password TDPID=DTDATA1A); SELECT FIRST_NAME, LAST_NAME FROM CONNECTION TO TERADATA (SELECT FIRST_NAME, LAST_NAME FROM INDIVIDUAL WHERE PARTY_ID IN (SELECT PARTY_ID, SUM(TOTALPAID_AMT) FROM CUSTOMER_SUMMARY HAVING SUM(TOTALPAID_AMT)>90)); QUIT; 58
59 The PROC SQL PASS-Through Facility Repeat the previous query with a little different subquery. PROC SQL INOBS=100; CONNECT TO TERADATA(USER=userid PASSWORD=password TDPID=DTDATA1A); SELECT FIRST_NAME, LAST_NAME FROM CONNECTION TO TERADATA (SELECT FIRST_NAME, LAST_NAME FROM INDIVIDUAL WHERE PARTY_ID IN (SELECT PARTY_ID FROM CUSTOMER_SUMMARY WHERE TOTALPAID_AMT >90)); QUIT; 59
60 Select Expression Subqueries Create a 'Y','N' flag if customer had purchase in the last six months PROC SQL; CREATE TABLE Flagnopurch_last180 as SELECT C.*, Case When (Custid in (SELECT Custid FROM Orders WHERE Today() - Odate le 180) ) Then 'y' Else 'n' End as Pflag FROM Customers C ; Quit; Proc Print Data=Flagnopurch_last180; Title 'Flagnopurchlast180'; Run; 60
61 Select Expression Subqueries (continued) The resulting output: Flagnopurch_last180 Obs Ctate Countrycode Custid Pflag 1 WI US 1234 y 2 IL US 1235 y 3 WI US 1236 n 4 OR US 1237 y 5 VI VI 1238 y 61
62 More Select Subqueries Summarize all order amounts in the last year. PROC SQL; CREATE TABLE Summary12months as SELECT C.Custid, (SELECT Sum(O.OrderAmt) FROM Orders O WHERE Today() - Odate lt 365 and C.custid = O.custid ) as TotalOrderAmt FROM Customers C; Quit; Proc Print Data=Summary12months; Title 'Summary12months'; Run; 62
63 More Select Subqueries The resulting output. Summary12months Total Obs Custid OrderAmt
64 A WHERE Subquery An Inner join shows only customers with order amounts. PROC SQL; CREATE TABLE Summary_12months as SELECT Custid, Sum(O.OrderAmt) as TotalOrderAmt FROM Orders O WHERE Custid in (SELECT C.Custid FROM Customers C INNER JOIN Orders O on C.Custid = O.Custid ) AND Today() - Odate lt 365 GROUP BY custid; Quit; Proc Print Data=Summary_12months; Title 'Summary_12months'; Run; 64
65 A WHERE Subquery The resulting output. Summary_12months Total Obs Custid OrderAmt
66 Inline View A subquery on the FROM expression is called an INLINE view. PROC SQL; CREATE TABLE Summary12months_i as SELECT C.Custid, O.TotalOrderAmt FROM (select custid, sum(orderamt) as TotalOrderAmt from orders WHERE Today() - Odate lt 365 group by custid ) as o, Customers as C where C.custid = O.custid; Quit; Proc Print Data=Summary12months_i; Title 'Summary12months_i'; Run; 66
67 Inline View The resulting output. Summary12months_i Total Obs Custid OrderAmt
68 Standard SQL Joining The previous results can be gotten with standard joining. PROC SQL; CREATE TABLE Summary12months_j as SELECT C.Custid, sum(o.orderamt) as TotalOrderAmt FROM orders o, Customers as C where C.custid = O.custid and Today() - Odate lt 365 group by c. custid ; Quit; Proc Print Data=Summary12months_j; Title 'Summary12months_j'; Run; 68
69 Standard SQL Joining The resulting output. Summary12months_j Total Obs Custid OrderAmt
70 SAS Merging PROC SORT and a DATA step can also produce the same results.. PROC proc sort data=orders; by custid; WHERE Today() - Odate lt 365; run; proc sort data=customers; by custid; run; data mergeds(keep=custid totalorderamt); merge orders(in=o) customers(in=c); by custid; if o and c; if first.custid then totalorderamt=0; totalorderamt+orderamt; put _all_; if last.custid; run; Proc Print Data=mergeds; Title 'Mergeds'; Run; 70
71 SAS Merging The resulting output. Mergeds Obs Custid totalorderamt
72 Combining a Join with a Subquery Example: You want the city nearest to each city in the USCITYCOORDS table. The query must: first select a city A compute the distance from city A to every other city finally select the city with the minimum distance from city A. This can be done by joining the USCITYCOORDS table to itself (self-join) and then determining the closest distance between cities by using another self-join in a subquery. The following example is explained in detail in the PROC SQL documentation. 72
73 Combining a Join with a Subquery The resulting output: proc sql outobs=10; title 'Neighboring Cities'; select a.city format=$10., a.state, a.latitude 'Lat', a.longitude 'Long', b.city format=$10., b.state, b.latitude 'Lat', b.longitude 'Long', sqrt(((b.latitude-a.latitude)**2) + ((b.longitude-a.longitude)**2)) as dist format=6.1 from sql.uscitycoords a, sql.uscitycoords b where a.city ne b.city and calculated dist = (select min(sqrt(((d.latitudec.latitude)**2) + ((d.longitude-c.longitude)**2))) from sql.uscitycoords c, sql.uscitycoords d where c.city = a.city and c.state = a.state and d.city ne c.city) order by a.city; 73
74 Combining a Join with a Subquery The resulting output. Neighboring Cities City State Lat Long City State Lat Long dist Albany NY Hartford CT Albuquerqu NM Santa Fe NM Amarillo TX Carlsbad NM Anchorage AK Nome AK Annapolis MD Washington DC Atlanta GA Knoxville TN Augusta ME Portland ME Austin TX San Antoni TX Baker OR Lewiston ID Baltimore MD Dover DE
75 Combining a Join with a Subquery Process: Outer query joins the table to itself and finds distance between first city A1 in table A and city B2 (the first city not equal to city A1) in Table B. PROC SQL then runs the subquery. The subquery does another self-join and calculates min distance between city A1 and all other cities in the table other than city A1. The outer query tests to see whether the distance between cities A1 and B2 = minimum distance that was calculated by the subquery. If they are equal, then a row with cities A1 and B2, coordinates and distance is written. 75
76 When to Use Subqueries Versus Joins What is the difference between the subqueries and joins? If you need data from more than one table, you must join them. If you need to combine different related rows in a single table, the table can be joined with itself. Use subqueries when the result you want requires more than one query and each subquery provides a subset of the table involved in the query. If a membership question is asked, then a subquery is usually used. EXISTS or NOT EXISTS operates only in a subquery. Some subqueries will be changed to a join by the SQL optimizer. Many queries can be written as either a subquery or a join. Generally, the join will be more efficient because a subquery is unable to directly apply the WHERE condition. 76
77 Additional Examples Create a Dashboard table with multiple statistics on one row. proc sql; create table dashboard as select distinct (select sum(amount) from sales where salesid='900009' ) as sum format=comma8.2, (select avg(amount) from sales where salesid='900009' ) as avg format=comma8.2, (select sum(amount) from sales where salesid='900386' ) as sum format=comma8.2, (select avg(amount) from sales where salesid='900386' ) as avg format=comma8.2 from sales ; quit; 77
78 Additional Examples The Dashboard output. dashboard Obs sum avg sum avg , ,
79 Additional Examples Use a SQL query to display all columns if CUSTID is duplicated. PROC SQL; SELECT * FROM CONTACTS GROUP BY CUSTID HAVING COUNT(*) > 1 ORDER BY CUSTID, SALESID, DATE; QUIT; 337 PROC SQL; 338 SELECT * 339 FROM CONTACTS 340 GROUP BY CUSTID 341 HAVING COUNT(*) > order by custid, salesid, date; NOTE: The query requires remerging summary statistics back with the original data. 343 QUIT; Notes: The program worked correctly. Is note important? 79
80 Additional Examples The resulting report. Duplicated Custids by Query CUSTID SALESID DATE ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ /05/ /04/ /04/ /02/ /05/ /02/ /04/ /04/ /03/ /04/ /03/ /04/ /04/ /05/ /04/ /02/ /02/99 80
81 Additional Examples Coding as a subquery, eliminates the remerging message. 321 PROC SQL; 322 SELECT * 323 FROM CONTACTS 324 where custid in 325 (SELECT CUSTID 326 FROM CONTACTS 327 GROUP BY CUSTID 328 HAVING COUNT(*) > 1) 329 order by custid, salesid, date; 330 QUIT; NOTE: PROCEDURE SQL used (Total process time): 81
82 Additional Examples The resulting report is identical. Duplicated Custids by Subquery CUSTID SALESID DATE ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ /05/ /04/ /04/ /02/ /05/ /02/ /04/ /04/ /03/ /04/ /03/ /04/ /04/ /05/ /04/ /02/ /02/99 82
83 Conclusions PROC SQL subqueries provide more methods for joining, row selection, and much, much more. Like with any programming language, experience will show more and more value in subqueries. Remembering that subqueries usually return a single value makes understanding easier. Subqueries that return multiple values are compared to a single value with IN, ANY, ALL. Most subqueries are on WHERE, HAVING, but can appear other places. Performance needs to be benchmarked. Good commenting and documentation is crucial however code is written. 83
84 Contact Us SAS Training, Consulting, & Help Desk Services 2997 Yarmouth Greenway Drive Madison, WI (608) Fax (608) Steve First President 84
Introduction to Proc SQL Steven First, Systems Seminar Consultants, Madison, WI
Paper #HW02 Introduction to Proc SQL Steven First, Systems Seminar Consultants, Madison, WI ABSTRACT PROC SQL is a powerful Base SAS Procedure that combines the functionality of DATA and PROC steps into
Katie Minten Ronk, Steve First, David Beam Systems Seminar Consultants, Inc., Madison, WI
Paper 191-27 AN INTRODUCTION TO PROC SQL Katie Minten Ronk, Steve First, David Beam Systems Seminar Consultants, Inc., Madison, WI ABSTRACT PROC SQL is a powerful Base SAS 7 Procedure that combines the
Introduction to Proc SQL Katie Minten Ronk, Systems Seminar Consultants, Madison, WI
Paper 268-29 Introduction to Proc SQL Katie Minten Ronk, Systems Seminar Consultants, Madison, WI ABSTRACT PROC SQL is a powerful Base SAS Procedure that combines the functionality of DATA and PROC steps
AN INTRODUCTION TO THE SQL PROCEDURE Chris Yindra, C. Y. Associates
AN INTRODUCTION TO THE SQL PROCEDURE Chris Yindra, C Y Associates Abstract This tutorial will introduce the SQL (Structured Query Language) procedure through a series of simple examples We will initially
Chapter 1 Overview of the SQL Procedure
Chapter 1 Overview of the SQL Procedure 1.1 Features of PROC SQL...1-3 1.2 Selecting Columns and Rows...1-6 1.3 Presenting and Summarizing Data...1-17 1.4 Joining Tables...1-27 1-2 Chapter 1 Overview of
Performing Queries Using PROC SQL (1)
SAS SQL Contents Performing queries using PROC SQL Performing advanced queries using PROC SQL Combining tables horizontally using PROC SQL Combining tables vertically using PROC SQL 2 Performing Queries
Outline. SAS-seminar Proc SQL, the pass-through facility. What is SQL? What is a database? What is Proc SQL? What is SQL and what is a database
Outline SAS-seminar Proc SQL, the pass-through facility How to make your data processing someone else s problem What is SQL and what is a database Quick introduction to Proc SQL The pass-through facility
Effective Use of SQL in SAS Programming
INTRODUCTION Effective Use of SQL in SAS Programming Yi Zhao Merck & Co. Inc., Upper Gwynedd, Pennsylvania Structured Query Language (SQL) is a data manipulation tool of which many SAS programmers are
Information Systems SQL. Nikolaj Popov
Information Systems SQL Nikolaj Popov Research Institute for Symbolic Computation Johannes Kepler University of Linz, Austria [email protected] Outline SQL Table Creation Populating and Modifying
Oracle SQL. Course Summary. Duration. Objectives
Oracle SQL Course Summary Identify the major structural components of the Oracle Database 11g Create reports of aggregated data Write SELECT statements that include queries Retrieve row and column data
Tips, Tricks, and Techniques from the Experts
Tips, Tricks, and Techniques from the Experts Presented by Katie Ronk 2997 Yarmouth Greenway Drive, Madison, WI 53711 Phone: (608) 278-9964 Web: www.sys-seminar.com Systems Seminar Consultants, Inc www.sys-seminar.com
Foundations & Fundamentals. A PROC SQL Primer. Matt Taylor, Carolina Analytical Consulting, LLC, Charlotte, NC
A PROC SQL Primer Matt Taylor, Carolina Analytical Consulting, LLC, Charlotte, NC ABSTRACT Most SAS programmers utilize the power of the DATA step to manipulate their datasets. However, unless they pull
Structured Query Language (SQL)
Objectives of SQL Structured Query Language (SQL) o Ideally, database language should allow user to: create the database and relation structures; perform insertion, modification, deletion of data from
Oracle Database: SQL and PL/SQL Fundamentals
Oracle University Contact Us: 1.800.529.0165 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This course is designed to deliver the fundamentals of SQL and PL/SQL along
David M. Kroenke and David J. Auer Database Processing: Fundamentals, Design and Implementation
David M. Kroenke and David J. Auer Database Processing: Fundamentals, Design and Implementation Chapter Two: Introduction to Structured Query Language 2-1 Chapter Objectives To understand the use of extracted
2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA www.sybex.com
Essential SQL 2 Essential SQL This bonus chapter is provided with Mastering Delphi 6. It is a basic introduction to SQL to accompany Chapter 14, Client/Server Programming. RDBMS packages are generally
Using the SQL Procedure
Using the SQL Procedure Kirk Paul Lafler Software Intelligence Corporation Abstract The SQL procedure follows most of the guidelines established by the American National Standards Institute (ANSI). In
Financial Data Access with SQL, Excel & VBA
Computational Finance and Risk Management Financial Data Access with SQL, Excel & VBA Guy Yollin Instructor, Applied Mathematics University of Washington Guy Yollin (Copyright 2012) Data Access with SQL,
Oracle Database: SQL and PL/SQL Fundamentals NEW
Oracle University Contact Us: + 38516306373 Oracle Database: SQL and PL/SQL Fundamentals NEW Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training delivers the
The prerelease version of SQL was called SEQUEL (for Structured English Query Language), and some people still pronounce SQL as sequel.
23 SQL The SQL proc lets you execute SQL statements that operate on SAS data. SQL, Structured Query Language, is the closest thing there is to a standard language for retrieving data from databases. SQL
Oracle Database 12c: Introduction to SQL Ed 1.1
Oracle University Contact Us: 1.800.529.0165 Oracle Database 12c: Introduction to SQL Ed 1.1 Duration: 5 Days What you will learn This Oracle Database: Introduction to SQL training helps you write subqueries,
Oracle Database: SQL and PL/SQL Fundamentals
Oracle University Contact Us: +966 12 739 894 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training is designed to
Introduction to Microsoft Jet SQL
Introduction to Microsoft Jet SQL Microsoft Jet SQL is a relational database language based on the SQL 1989 standard of the American Standards Institute (ANSI). Microsoft Jet SQL contains two kinds of
SQL. Short introduction
SQL Short introduction 1 Overview SQL, which stands for Structured Query Language, is used to communicate with a database. Through SQL one can create, manipulate, query and delete tables and contents.
9.1 SAS. SQL Query Window. User s Guide
SAS 9.1 SQL Query Window User s Guide The correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2004. SAS 9.1 SQL Query Window User s Guide. Cary, NC: SAS Institute Inc. SAS
Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff
D80198GC10 Oracle Database 12c SQL and Fundamentals Summary Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff Level Professional Delivery Method Instructor-led
Fun with PROC SQL Darryl Putnam, CACI Inc., Stevensville MD
NESUG 2012 Fun with PROC SQL Darryl Putnam, CACI Inc., Stevensville MD ABSTRACT PROC SQL is a powerful yet still overlooked tool within our SAS arsenal. PROC SQL can create tables, sort and summarize data,
Chapter 9 Joining Data from Multiple Tables. Oracle 10g: SQL
Chapter 9 Joining Data from Multiple Tables Oracle 10g: SQL Objectives Identify a Cartesian join Create an equality join using the WHERE clause Create an equality join using the JOIN keyword Create a non-equality
Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification
Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Outline More Complex SQL Retrieval Queries
Week 4 & 5: SQL. SQL as a Query Language
Week 4 & 5: SQL The SQL Query Language Select Statements Joins, Aggregate and Nested Queries Insertions, Deletions and Updates Assertions, Views, Triggers and Access Control SQL 1 SQL as a Query Language
Paper 70-27 An Introduction to SAS PROC SQL Timothy J Harrington, Venturi Partners Consulting, Waukegan, Illinois
Paper 70-27 An Introduction to SAS PROC SQL Timothy J Harrington, Venturi Partners Consulting, Waukegan, Illinois Abstract This paper introduces SAS users with at least a basic understanding of SAS data
Paper 109-25 Merges and Joins Timothy J Harrington, Trilogy Consulting Corporation
Paper 109-25 Merges and Joins Timothy J Harrington, Trilogy Consulting Corporation Abstract This paper discusses methods of joining SAS data sets. The different methods and the reasons for choosing a particular
Microsoft Access Lesson 5: Structured Query Language (SQL)
Microsoft Access Lesson 5: Structured Query Language (SQL) Structured Query Language (pronounced S.Q.L. or sequel ) is a standard computing language for retrieving information from and manipulating databases.
COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries
COMP 5138 Relational Database Management Systems Week 5 : Basic COMP5138 "Relational Database Managment Systems" J. Davis 2006 5-1 Today s Agenda Overview Basic Queries Joins Queries Aggregate Functions
SQL SELECT Query: Intermediate
SQL SELECT Query: Intermediate IT 4153 Advanced Database J.G. Zheng Spring 2012 Overview SQL Select Expression Alias revisit Aggregate functions - complete Table join - complete Sub-query in where Limiting
Handling Missing Values in the SQL Procedure
Handling Missing Values in the SQL Procedure Danbo Yi, Abt Associates Inc., Cambridge, MA Lei Zhang, Domain Solutions Corp., Cambridge, MA ABSTRACT PROC SQL as a powerful database management tool provides
Database Query 1: SQL Basics
Database Query 1: SQL Basics CIS 3730 Designing and Managing Data J.G. Zheng Fall 2010 1 Overview Using Structured Query Language (SQL) to get the data you want from relational databases Learning basic
Access Queries (Office 2003)
Access Queries (Office 2003) Technical Support Services Office of Information Technology, West Virginia University OIT Help Desk 293-4444 x 1 oit.wvu.edu/support/training/classmat/db/ Instructor: Kathy
Five Little Known, But Highly Valuable, PROC SQL Programming Techniques. a presentation by Kirk Paul Lafler
Five Little Known, But Highly Valuable, PROC SQL Programming Techniques a presentation by Kirk Paul Lafler Copyright 1992-2014 by Kirk Paul Lafler and Software Intelligence Corporation. All rights reserved.
SQL Programming. Student Workbook
SQL Programming Student Workbook 2 SQL Programming SQL Programming Published by itcourseware, Inc., 7245 South Havana Street, Suite 100, Englewood, CO 80112 Contributing Authors: Denise Geller, Rob Roselius,
Oracle Database 10g: Introduction to SQL
Oracle University Contact Us: 1.800.529.0165 Oracle Database 10g: Introduction to SQL Duration: 5 Days What you will learn This course offers students an introduction to Oracle Database 10g database technology.
SQL - QUICK GUIDE. Allows users to access data in relational database management systems.
http://www.tutorialspoint.com/sql/sql-quick-guide.htm SQL - QUICK GUIDE Copyright tutorialspoint.com What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating
Querying Microsoft SQL Server
Course 20461C: Querying Microsoft SQL Server Module 1: Introduction to Microsoft SQL Server 2014 This module introduces the SQL Server platform and major tools. It discusses editions, versions, tools used
Querying Microsoft SQL Server 20461C; 5 days
Lincoln Land Community College Capital City Training Center 130 West Mason Springfield, IL 62702 217-782-7436 www.llcc.edu/cctc Querying Microsoft SQL Server 20461C; 5 days Course Description This 5-day
The Query Builder: The Swiss Army Knife of SAS Enterprise Guide
Paper 1557-2014 The Query Builder: The Swiss Army Knife of SAS Enterprise Guide ABSTRACT Jennifer First-Kluge and Steven First, Systems Seminar Consultants, Inc. The SAS Enterprise Guide Query Builder
Preparing your data for analysis using SAS. Landon Sego 24 April 2003 Department of Statistics UW-Madison
Preparing your data for analysis using SAS Landon Sego 24 April 2003 Department of Statistics UW-Madison Assumptions That you have used SAS at least a few times. It doesn t matter whether you run SAS in
SAS 9.3 SQL Procedure
SAS 9.3 SQL Procedure User s Guide SAS Documentation The correct bibliographic citation for this manual is as follows: SAS Institute Inc 2011. SAS 9.3 SQL Procedure User s Guide. Cary, NC: SAS Institute
ABSTRACT INTRODUCTION SAS AND EXCEL CAPABILITIES SAS AND EXCEL STRUCTURES
Paper 85-2010 Choosing the Right Tool from Your SAS and Microsoft Excel Tool Belt Steven First and Jennifer First, Systems Seminar Consultants, Madison, Wisconsin ABSTRACT There are over a dozen ways to
Oracle 10g PL/SQL Training
Oracle 10g PL/SQL Training Course Number: ORCL PS01 Length: 3 Day(s) Certification Exam This course will help you prepare for the following exams: 1Z0 042 1Z0 043 Course Overview PL/SQL is Oracle's Procedural
Your Database Can Do SAS Too!
Paper 2004-2015 Your Database Can Do SAS Too! Harry Droogendyk, Stratia Consulting Inc. ABSTRACT How often have you pulled oodles of data out of the corporate data warehouse down into SAS for additional
CHAPTER 1 Overview of SAS/ACCESS Interface to Relational Databases
3 CHAPTER 1 Overview of SAS/ACCESS Interface to Relational Databases About This Document 3 Methods for Accessing Relational Database Data 4 Selecting a SAS/ACCESS Method 4 Methods for Accessing DBMS Tables
Course ID#: 1401-801-14-W 35 Hrs. Course Content
Course Content Course Description: This 5-day instructor led course provides students with the technical skills required to write basic Transact- SQL queries for Microsoft SQL Server 2014. This course
Oracle Database: Introduction to SQL
Oracle University Contact Us: +381 11 2016811 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn Understanding the basic concepts of relational databases ensure refined code by developers.
Programming with SQL
Unit 43: Programming with SQL Learning Outcomes A candidate following a programme of learning leading to this unit will be able to: Create queries to retrieve information from relational databases using
Relational Database: Additional Operations on Relations; SQL
Relational Database: Additional Operations on Relations; SQL Greg Plaxton Theory in Programming Practice, Fall 2005 Department of Computer Science University of Texas at Austin Overview The course packet
Introduction to SQL and SQL in R. LISA Short Courses Xinran Hu
Introduction to SQL and SQL in R LISA Short Courses Xinran Hu 1 Laboratory for Interdisciplinary Statistical Analysis LISA helps VT researchers benefit from the use of Statistics Collaboration: Visit our
SQL Server. 2012 for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach
TRAINING & REFERENCE murach's SQL Server 2012 for developers Bryan Syverson Joel Murach Mike Murach & Associates, Inc. 4340 N. Knoll Ave. Fresno, CA 93722 www.murach.com [email protected] Expanded
Oracle Database: Introduction to SQL
Oracle University Contact Us: 1.800.529.0165 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn View a newer version of this course This Oracle Database: Introduction to SQL training
David M. Kroenke and David J. Auer Database Processing 11 th Edition Fundamentals, Design, and Implementation. Chapter Objectives
David M. Kroenke and David J. Auer Database Processing 11 th Edition Fundamentals, Design, and Implementation Chapter One: Introduction 1-1 Chapter Objectives To understand the nature and characteristics
Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.
Retrieving Data Using the SQL SELECT Statement Objectives After completing this lesson, you should be able to do the following: List the capabilities of SQL SELECT statements Execute a basic SELECT statement
Using Multiple Operations. Implementing Table Operations Using Structured Query Language (SQL)
Copyright 2000-2001, University of Washington Using Multiple Operations Implementing Table Operations Using Structured Query Language (SQL) The implementation of table operations in relational database
Introducing Microsoft SQL Server 2012 Getting Started with SQL Server Management Studio
Querying Microsoft SQL Server 2012 Microsoft Course 10774 This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL queries for Microsoft SQL Server
SQL Server 2008 Core Skills. Gary Young 2011
SQL Server 2008 Core Skills Gary Young 2011 Confucius I hear and I forget I see and I remember I do and I understand Core Skills Syllabus Theory of relational databases SQL Server tools Getting help Data
More on SQL. Juliana Freire. Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan
More on SQL Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan SELECT A1, A2,, Am FROM R1, R2,, Rn WHERE C1, C2,, Ck Interpreting a Query
Querying Microsoft SQL Server Course M20461 5 Day(s) 30:00 Hours
Área de formação Plataforma e Tecnologias de Informação Querying Microsoft SQL Introduction This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL
Your Database Can Do SAS Too!
SESUG 2014 Paper AD-57 Your Database Can Do SAS Too! Harry Droogendyk, Stratia Consulting Inc., Lynden, ON ABSTRACT How often have you pulled oodles of data out of the corporate data warehouse down into
SQL Basics. Introduction to Standard Query Language
SQL Basics Introduction to Standard Query Language SQL What Is It? Structured Query Language Common Language For Variety of Databases ANSI Standard BUT. Two Types of SQL DML Data Manipulation Language
MOC 20461C: Querying Microsoft SQL Server. Course Overview
MOC 20461C: Querying Microsoft SQL Server Course Overview This course provides students with the knowledge and skills to query Microsoft SQL Server. Students will learn about T-SQL querying, SQL Server
DBMS / Business Intelligence, SQL Server
DBMS / Business Intelligence, SQL Server Orsys, with 30 years of experience, is providing high quality, independant State of the Art seminars and hands-on courses corresponding to the needs of IT professionals.
More Tales from the Help Desk: Solutions for Simple SAS Mistakes Bruce Gilsen, Federal Reserve Board
More Tales from the Help Desk: Solutions for Simple SAS Mistakes Bruce Gilsen, Federal Reserve Board INTRODUCTION In 20 years as a SAS consultant at the Federal Reserve Board, I have seen SAS users make
T-SQL STANDARD ELEMENTS
T-SQL STANDARD ELEMENTS SLIDE Overview Types of commands and statement elements Basic SELECT statements Categories of T-SQL statements Data Manipulation Language (DML*) Statements for querying and modifying
PROC SQL for DATA Step Die-Hards Christianna S. Williams, Yale University
PROC SQL for DATA Step Die-Hards Christianna S. Williams, Yale University ABSTRACT PROC SQL can be rather intimidating for those who have learned SAS data management techniques exclusively using the DATA
Using SQL Queries to Insert, Update, Delete, and View Data: Joining Multiple Tables. Lesson C Objectives. Joining Multiple Tables
Using SQL Queries to Insert, Update, Delete, and View Data: Joining Multiple Tables Wednesay 9/24/2014 Abdou Illia MIS 4200 - Fall 2014 Lesson C Objectives After completing this lesson, you should be able
Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems
CSC 74 Database Management Systems Topic #0: SQL Part A: Data Definition Language (DDL) Spring 00 CSC 74: DBMS by Dr. Peng Ning Spring 00 CSC 74: DBMS by Dr. Peng Ning Schema and Catalog Schema A collection
One problem > Multiple solutions; various ways of removing duplicates from dataset using SAS Jaya Dhillon, Louisiana State University
One problem > Multiple solutions; various ways of removing duplicates from dataset using SAS Jaya Dhillon, Louisiana State University ABSTRACT In real world, analysts seldom come across data which is in
MOC 20461 QUERYING MICROSOFT SQL SERVER
ONE STEP AHEAD. MOC 20461 QUERYING MICROSOFT SQL SERVER Length: 5 days Level: 300 Technology: Microsoft SQL Server Delivery Method: Instructor-led (classroom) COURSE OUTLINE Module 1: Introduction to Microsoft
Oracle Database: Introduction to SQL
Oracle University Contact Us: 1.800.529.0165 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn This Oracle Database: Introduction to SQL training teaches you how to write subqueries,
SQL Nested & Complex Queries. CS 377: Database Systems
SQL Nested & Complex Queries CS 377: Database Systems Recap: Basic SQL Retrieval Query A SQL query can consist of several clauses, but only SELECT and FROM are mandatory SELECT FROM
David M. Kroenke and David J. Auer Database Processing 12 th Edition
David M. Kroenke and David J. Auer Database Processing 12 th Edition Fundamentals, Design, and Implementation ti Chapter One: Introduction Modified & translated by Walter Chen Dept. of Civil Engineering
Intro to Embedded SQL Programming for ILE RPG Developers
Intro to Embedded SQL Programming for ILE RPG Developers Dan Cruikshank DB2 for i Center of Excellence 1 Agenda Reasons for using Embedded SQL Getting started with Embedded SQL Using Host Variables Using
Aggregating Data Using Group Functions
Aggregating Data Using Group Functions Objectives Capter 5 After completing this lesson, you should be able to do the following: Identify the available group functions Describe the use of group functions
Microsoft Access 3: Understanding and Creating Queries
Microsoft Access 3: Understanding and Creating Queries In Access Level 2, we learned how to perform basic data retrievals by using Search & Replace functions and Sort & Filter functions. For more complex
SAS Views The Best of Both Worlds
Paper 026-2010 SAS Views The Best of Both Worlds As seasoned SAS programmers, we have written and reviewed many SAS programs in our careers. What I have noticed is that more often than not, people who
The join operation allows you to combine related rows of data found in two tables into a single result set.
(Web) Application Development With Ian Week 3 SQL with Multiple Tables Join The join operation allows you to combine related rows of data found in two tables into a single result set. It works similarly
Introduction to SAS Mike Zdeb (402-6479, [email protected]) #122
Mike Zdeb (402-6479, [email protected]) #121 (11) COMBINING SAS DATA SETS There are a number of ways to combine SAS data sets: # concatenate - stack data sets (place one after another) # interleave - stack
Paper TU_09. Proc SQL Tips and Techniques - How to get the most out of your queries
Paper TU_09 Proc SQL Tips and Techniques - How to get the most out of your queries Kevin McGowan, Constella Group, Durham, NC Brian Spruell, Constella Group, Durham, NC Abstract: Proc SQL is a powerful
P_Id LastName FirstName Address City 1 Kumari Mounitha VPura Bangalore 2 Kumar Pranav Yelhanka Bangalore 3 Gubbi Sharan Hebbal Tumkur
SQL is a standard language for accessing and manipulating databases. What is SQL? SQL stands for Structured Query Language SQL lets you access and manipulate databases SQL is an ANSI (American National
Instant SQL Programming
Instant SQL Programming Joe Celko Wrox Press Ltd. INSTANT Table of Contents Introduction 1 What Can SQL Do for Me? 2 Who Should Use This Book? 2 How To Use This Book 3 What You Should Know 3 Conventions
Course 20461C: Querying Microsoft SQL Server Duration: 35 hours
Course 20461C: Querying Microsoft SQL Server Duration: 35 hours About this Course This course is the foundation for all SQL Server-related disciplines; namely, Database Administration, Database Development
SAS PASSTHRU to Microsoft SQL Server using ODBC Nina L. Werner, Madison, WI
Paper SA-03-2014 SAS PASSTHRU to Microsoft SQL Server using ODBC Nina L. Werner, Madison, WI ABSTRACT I wish I could live in SAS World I do much of my data analysis there. However, my current environment
Oracle Database: SQL and PL/SQL Fundamentals NEW
Oracle University Contact Us: 001-855-844-3881 & 001-800-514-06-97 Oracle Database: SQL and PL/SQL Fundamentals NEW Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals
SQL SUBQUERIES: Usage in Clinical Programming. Pavan Vemuri, PPD, Morrisville, NC
PharmaSUG 2013 Poster # P015 SQL SUBQUERIES: Usage in Clinical Programming Pavan Vemuri, PPD, Morrisville, NC ABSTRACT A feature of PROC SQL which provides flexibility to SAS users is that of a SUBQUERY.
Title. Syntax. stata.com. odbc Load, write, or view data from ODBC sources. List ODBC sources to which Stata can connect odbc list
Title stata.com odbc Load, write, or view data from ODBC sources Syntax Menu Description Options Remarks and examples Also see Syntax List ODBC sources to which Stata can connect odbc list Retrieve available
SAS Programming Tips, Tricks, and Techniques
SAS Programming Tips, Tricks, and Techniques A presentation by Kirk Paul Lafler Copyright 2001-2012 by Kirk Paul Lafler, Software Intelligence Corporation All rights reserved. SAS is the registered trademark
ICAB4136B Use structured query language to create database structures and manipulate data
ICAB4136B Use structured query language to create database structures and manipulate data Release: 1 ICAB4136B Use structured query language to create database structures and manipulate data Modification
Unit 3. Retrieving Data from Multiple Tables
Unit 3. Retrieving Data from Multiple Tables What This Unit Is About How to retrieve columns from more than one table or view. What You Should Be Able to Do Retrieve data from more than one table or view.
