【发布时间】:2021-08-11 15:43:10
【问题描述】:
我有一个数据如下-Credit card transaction data
我需要为每张信用卡添加一个计数器变量——为每个日期和交易国家类型。应该是这样的 -Expected result with New counter variable
我正在按组(第一个。最后一个)的帮助下尝试这个,但没有得到预期的结果。此问题陈述需要帮助。谢谢!!
【问题讨论】:
我有一个数据如下-Credit card transaction data
我需要为每张信用卡添加一个计数器变量——为每个日期和交易国家类型。应该是这样的 -Expected result with New counter variable
我正在按组(第一个。最后一个)的帮助下尝试这个,但没有得到预期的结果。此问题陈述需要帮助。谢谢!!
【问题讨论】:
您在应用first. 和last. 概念方面走在了正确的轨道上。让我知道这是否有效。
proc sort data=work.trans_data;
by cc_no dot country ts;
run;
data work.trans_data_cnt;
set work.trans_data;
by cc_no dot country ts;
/*This will assign the first row of the cc_no, dot, country = 1*/
if first.cc_no = 1 and first.dot = 1 and first.country = 1 then
counter = 1;
/*Restart counter, we have switched country, but are in the same cc_no and dot.*/
else if first.country = 1 then
counter = 1;
/*Increment the counter, we are within the same cc_no, dot, country.*/
else
counter + 1;
run;
【讨论】: