全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1618 2
2010-09-12
Let's start with a table called "Pets"

Job:
1. Create a new table (call it NewPets)
2. One column equals Max(Food), whereas Food was a column in Pets that registered how much (say, grams) each meal contains
3. Add one column (FoodStats) in NewPets whereas:
if Max(Food)<1, FoodStats="NIL"
if 1=<Max(Food)<=10, FoodStats="LITTLE"
if 11<=Max(Food) <=50, FoodStats="SOME"
and so on....

What should the SQL be like?  Can the steps be completed in one run or should they be separated into several steps?

Thanks!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2010-9-12 18:53:04
case when 吧
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-9-13 10:08:40
data pets;
   input type $ number food;
   cards;
Cat 1 6
Cat 2 8
Cat 3 5
Dog 1 18
Dog 2 33
Dog 3 12
Bug 1 0.2
Bug 2 0.4
Bug 3 0.1
;

proc sql;
     create table newpets as
             select distinct type,max(food) as max_food,
                                          case
                    when Max(Food)<1 then "NIL"
                    when 1<=Max(Food) <=10 then "LITTLE"
                    when 11 <= Max(Food) <=50 then "SOME"
                   else " " end as foodstats
           from pets
         group by type;
quit;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群