【问题标题】:Need help for a SAS problem to get a new variable created basis on the conditional data需要帮助解决 SAS 问题以根据条件数据创建新变量
【发布时间】:2021-08-11 15:43:10
【问题描述】:

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

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

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

【问题讨论】:

    标签: sas proc-sql


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-23
      • 2021-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多