需要帮助解决 SAS 问题以根据条件数据创建新变量

Need help for a SAS problem to get a new variable created basis on the conditional data

我有一个数据如下- Credit card transaction data

我需要为每张信用卡添加一个计数器变量——针对每个日期和交易国家/地区类型。应该是这样的 -Expected result with New counter variable

我正在按组(first.last.)的帮助尝试这个,但没有得到预期的结果。此问题陈述需要帮助。谢谢!!

您在应用概念 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;