SQL procedure User ' s Guide

Source: Internet
Author: User

1. Ordering the SELECT Statement:

1.select

2. From

3. Where

4. Group by

5. Having

6. Order by

Select sum (Population)  from sql.countries Group  by Continent  having inch ('Asia''Europe') Order  by Continent;

2. The outobs=option limits the number of rows in the output. Outobs= is similar
To the Obs=data set option

proc sql Outobs="U.S. Cities with their states and coordinates ' ; Select *  from Sql.uscitycoords;

3. The keyword DISTINCT can eliminate the duplicate rows from the results

PROC SQL;     ' Continents of the States ' ;     Select distinct Continent          from Sql.unitedstates;quit;

4. Determing the structure of a Table:

The DESCRIBE table Statement:obtain a list of all of the columns in a table and

their attributes.

proc SQL;     Table Sql.unitedstates;quit;

Creating New Columns:
Adding Text to Output:

proc sql Outobs="U.S. Postal Codes"; Select ' Postal Code for ' '  is ' , Code  from Sql.postalcodes;quit

Proc SQL Outobs="U.S. Postal Codes';' Postal codefor "is", Code label= ' # ' from sql.postalcodes;quit   

Referring to a calculated Column by Alias (keyword:calculated)

procSQL Outobs= A; title'Range of temperatures in Celsius';SelectCity, (Avghigh-  +)* 5/9  asHIGHC format=5.1, (Avglow-  +)* 5/9  asLOWC format=5.1, (Calculated HIGHC-calculated LOWC) asRange format=4.1 fromSql.worldtemps;

Assigning Values conditionally:

1. Using A simple CASE expression

2. Using the Case-operand from

procSQL Outobs= A; title'Climate Zones of World Cities'; SelectCity , Country, Latitude, Case         whenLatitude GT the  Then 'North Frigid'         when  theGE Latitude GE at  Then 'North Temperate'         when  atGT Latitude GT- at  Then 'Torrid'         when - atGE Latitude GE- the  Then 'South Temperate'        Else 'South Frigid'    End  asClimatezone fromSql.worldcitycoordsOrder  byCity ; procSQL Outobs= A; title'assigning regions to continents'; SelectName, Continent, CaseContinent when 'North America'  Then 'Continental U.S.'         when 'Oceania'  Then 'Pacific Islands'        Else 'None'    End  as Region fromSql.unitedstates;

SQL procedure User ' s Guide

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.