zoukankan      html  css  js  c++  java
  • SQL procedure User's Guide(Single Table )

    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;

     Replacing Missing Values--> Coalesce function enables you to replace missing

                     values in a column with a new value that you specify.

    proc sql;
    title 'Continental Low Points';
    select Name, coalesce(LowPoint, 'Not Available') as LowPoint
    from sql.continents;

    Specifying Column Attributes:
      1. FORMAT=

      2. INFORMAT=

      3. LABEL=

      4. LENGTH=

    proc sql outobs=12;
    title 'Areas of U.S. States in Square Miles';
    select Name label='State', Area format=comma10.
    from sql.unitedstates;

    Sorting Data:
      ORDER BY Column

    proc sql outobs=12;
    title 'World Topographical Features';
    select Name, Type
        from sql.features
        order by Type desc, Name;

      Sorting by Column Position

    proc sql outobs=12;
    title 'World Population Densities per Square Mile';
        select Name, Population format=comma12., Area format=comma8.,
        Population/Area format=comma10. label='Density'
        from sql.countries
        order by 4 desc;

     Retrieving Rows That Satisfy a Condition:

      1.Using a Simple WHERE Clause  

    proc sql outobs=12;
    title 'Countries in Europe';
    select Name, Population format=comma10.
    from sql.countries
    where Continent = 'Europe';

      2.Retrieving Rows Based on a Comparison

      3. Retrieving Rows That Satisfy Multiple Conditions

      4.Using Other Conditional Operators:

    Using Aggregate Functions

      1. Using Aggregate Function with Unique Values

         Counting Unique Values:You can use DISTINCT with an aggregate function to cause the function to use only unique values from a column.

    proc sql;
    title 'Number of Continents in the Countries Table';
    select count(distinct Continent) as Count
    from sql.countries;

      2.Counting Nonmissing Values:

    proc sql;
    title 'Countries for Which a Continent is Listed';
    select count(Continent) as Count
    from sql.countries;

     3.Counting All Rows:

    proc sql;
    title 'Number of Countries in the Sql.Countries Table';
    select count(*) as Number
    from sql.countries;

    Grouping Data

      Groupong by One Column

    Vaildating a Query

      The VALIDATE statement enables you to check the syntax of a query for correctness without submitting it to PROC SQL. PROC SQL displays a message in the 
      log to indicate whether the syntax is correct.

  • 相关阅读:
    bootstrap实战练习中涉及的知识点(很有用哦!)
    Markdown的最常用标记符号有哪些?
    队列的插入 和出列 阻塞 时间 问题
    ArrayBlockingQueue和LinkedBlockingQueue的使用
    自己总结 :并发队列ConcurrentLinkedQueue、阻塞队列AraayBlockingQueue、阻塞队列LinkedBlockingQueue 区别 和 使用场景总结
    战斗由客户端来做,后端来验证 方式 解决 一些弊端思路
    类 文件 右下角呈现 红色小圆圈,里面有一个J 标记
    苏州儿童医保
    Error: opening registry key 'SoftwareJavaSoftJava Runtime Environment' could not find java.dll
    intellj(idea) 编译项目时在warnings 页签框里 报 “xxx包不存在” 或 “找不到符号” 或 “未结束的字符串字面值” 或 “需要)” 或 “需要;”等错误提示
  • 原文地址:https://www.cnblogs.com/easy-wang/p/6421825.html
Copyright © 2011-2022 走看看