全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1795 1
2016-10-18
悬赏 300 个论坛币 已解决

有一道SAS作业题,怎麼编都做不出最后一张表的结果,求大神帮忙!


Identifying Extreme Valuesin Each Group of Data

The data set orion.customer_dim contains informationabout Orion Star customers.

Partial orion.customer_dim(77 Total Observations, 11 Total Variables)

                                                                                    Customer_

   Customer_ID    Customer_Name          Customer_Type                              BirthDate

             4    James Kvarniq          Orion Club members low activity            27JUN1978

             5    Sandrina Stephano      Orion Club Gold members mediumactivity    09JUL1983

             9    Cornelia Krahl         Orion Club Gold members mediumactivity    27FEB1978

            10    Karen Ballinger        Orion Club members high activity         18OCT1988

            11    Elke Wallstab          Orion Club members high activity         16AUG1978


Use First./Last.processing to create the report below. Show data on the oldest and youngestcustomers for each Customer_Type.

·   The variable o_ID is the Customer_ID value of the oldest customer and y_ID is the Customer_IDvalue of the youngest customer for each group.

·   Create a variable named agerange to indicate the spread betweenthese oldest and youngest customers.

·   Use Customer_BirthDate, rather than Customer_Age, for all age determinations because this is moreaccurate.

Partial PROC PRINT Output (7 Total Observations)

Oldest and Youngest Customers of eachCustomer Type

Customer_Type                                 oldest     youngest     o_ID    y_ID    agerange

Internet/CatalogCustomers                 08JUL1938    18AUG1973       29   54655      35.1

Orion  Club members high activity          28SEP1938    24OCT1990       89   46966      52.1

Orion  Club members medium activity        20JAN1938    16SEP1992   70059     2806      54.7

Orion Club Goldmembers high activity      16JAN1938    25JUL1988       50      39      50.5

Orion Club Goldmembers low activity       19DEC1973    21JUL1992   70201       13      18.6



!       There are several waysto obtain the number of years between two dates. Two possible techniques aredividing days by 365.25 or using the YRDIF function.

最佳答案

l1i2n3i4n5g 查看完整内容

proc sort data=orion.customer_dim; by Customer_Type BirthDate; run; data orion.customer_dim1; set orion.customer_dim; retain youngest y_ID; format youngest oldest date9. agerange 10.1; by Customer_Type BirthDate; if first.Customer_Type then do; youngest=BirthDate; y_ID=Customer_ID; end; if last.Customer_Type then do; oldest=BirthDate; o_ID=Customer_ID; end; if last.Customer ...
二维码

扫码加我 拉你入群

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

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

全部回复
2016-10-18 20:55:43
proc sort data=orion.customer_dim;
by Customer_Type BirthDate;
run;

data orion.customer_dim1;
set orion.customer_dim;
retain youngest y_ID;
format youngest oldest date9. agerange 10.1;
by Customer_Type BirthDate;
if first.Customer_Type then
do;
        youngest=BirthDate;
        y_ID=Customer_ID;
end;
if last.Customer_Type then
do;
        oldest=BirthDate;
        o_ID=Customer_ID;
end;
if last.Customer_Type;
agerange=(oldest-youngest)/365.25;
keep Customer_Type oldest youngest o_ID y_ID agerange;
run;

proc sql;
create table orion.customer_dim2 as select Customer_Type,oldest,youngest,o_ID,y_ID,agerange from orion.customer_dim1;
quit;
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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