【问题标题】:creating a new SAS variable group using an existing variable group使用现有变量组创建新的 SAS 变量组
【发布时间】:2017-03-07 02:01:31
【问题描述】:

我有一个包含以下 13 个字段的 SAS 数据集:

base_price tax_month1-12

base price 是产品在缴税前的价格,而 tax_month 是每个月需要征收的税款百分比。

我想创建一个新的变量组 tax_paid1-12,它是 base_price 和每个纳税月份的乘积。

在 SAS 中是否有一种有效的方法可以在不一次将字段乘以 1 的情况下执行此操作?未来的月数可能会有所不同,因此我不想硬编码变量组中的字段数。

【问题讨论】:

    标签: sas


    【解决方案1】:

    不幸的是,您需要额外的步骤来计算月数。

    您可以使用数组计算每个月的tax_paid

    data source;
        infile datalines;
        input base_price tax_month1 tax_month2 tax_month3;
    datalines;
    1 2 . 4
    5 6 7 8
    ;
    run;
    
    data _null_;
        set source;
        array tax_month(*) tax_month:;
        call symputx('n', dim(tax_month));
        stop;
    run;
    
    data result;
        set source;
    
        array tax_month(&n) tax_month1-tax_month&n;
        array tax_paid(&n) tax_paid1-tax_paid&n;
    
        do i = 1 to dim(tax_month);
            tax_paid(i) = base_price * tax_month(i);
        end;
    
        drop i;
    run;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-23
      • 2021-07-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多