select 'Postal code for', Name label='#', 'is', Code label='#'
from sql.postalcodes;
/*-------------------------------------------------------------------
Output 2.8 Calculating Values
-------------------------------------------------------------------*/
proc sql outobs=12;
title 'Low Temperatures in Celsius';
select City, (AvgLow - 32) * 5/9 format=4.1
from sql.worldtemps;
/*-------------------------------------------------------------------
Output 2.9 Assigning a Column Alias to a Calculated Column
-------------------------------------------------------------------*/
proc sql outobs=12;
title 'Low Temperatures in Celsius';
select City, (AvgLow - 32) * 5/9 as LowCelsius format=4.1
from sql.worldtemps;
/*-------------------------------------------------------------------
Output 2.10 Referring to a Calculated Column by Alias
-------------------------------------------------------------------*/
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;
/*-------------------------------------------------------------------
Output 2.11 Using a Simple CASE Expression
-------------------------------------------------------------------*/
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;
/*-------------------------------------------------------------------
Output 2.12 Using a CASE Expression in the CASE-OPERAND Form
-------------------------------------------------------------------*/
proc sql outobs=12;
title 'Assigning Regions to Continents';
Example Code: Using the SQL Procedure 395