首页 > 代码库 > SQL procedure User's Guide
SQL procedure User's Guide
1. Ordering the SELECT Statement:
1.select
2. From
3. Where
4. Group by
5. Having
6. Order by
select Continent, sum(Population) from sql.countries group by Continent having Continent in (‘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=12; title ‘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; title ‘Continents of the United 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; describe table sql.unitedstates; quit;
Creating New Columns:
Adding Text to Output:
proc sql outobs=12; title ‘U.S. Postal Codes‘; select ‘Postal code for‘, Name, ‘is‘, Code from sql.postalcodes; quit
proc sql outobs=12;
title ‘U.S. Postal Codes‘;
select ‘Postal code for‘, Name label=‘#‘, ‘is‘, Code label=‘#‘
from sql.postalcodes;
quit
Referring to a Calculated Column by Alias (keyword: Calculated)
proc sql outobs=12; title ‘Range of High and Low Temperatures in Celsius‘; select City, (AvgHigh - 32) * 5/9 as HighC format=5.1, (AvgLow - 32) * 5/9 as LowC format=5.1, (calculated HighC - calculated LowC) as Range format=4.1 from sql.worldtemps;
Assigning Values Conditionally:
1. Using a simple Case expression
2. Using the case-operand from
proc sql outobs=12; title ‘Climate Zones of World Cities‘; select City, Country, Latitude, case when Latitude gt 67 then ‘North Frigid‘ when 67 ge Latitude ge 23 then ‘North Temperate‘ when 23 gt Latitude gt -23 then ‘Torrid‘ when -23 ge Latitude ge -67 then ‘South Temperate‘ else ‘South Frigid‘ end as ClimateZone from sql.worldcitycoords order by City; proc sql outobs=12; title ‘Assigning Regions to Continents‘; select Name, Continent, case Continent when ‘North America‘ then ‘Continental U.S.‘ when ‘Oceania‘ then ‘Pacific Islands‘ else ‘None‘ end as Region from sql.unitedstates;
SQL procedure User's Guide
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。