如何标记两个选定行之间但不包括两个选定行的数据集中的记录?

时间:2016-11-30 22:12:57

标签: sas

我有一个如下所示的数据集:

 Category                 Amount

 SALES  
 Alcohol Sales            $33,436 
 Cigarette Sales          78,953 
 TOTAL SALES              645,860 
 Alcohol COS              22,313 
 Cigarette COS            59,098 
 Grocery CC Fees          1,956 
 Roller Grill Spoilage    432 
 TOTAL COST OF SALES      55,555

我想在“TOTAL SALES”和“TASAL COST OF SLAES”之间的所有内容中添加一个标志,因此输出将是这样的:

  Category               Amount       Flag

 SALES                            
 Alcohol Sales           $33,436 
 Cigarette Sales         78,953 
 TOTAL SALES             645,860       
 Alcohol COS             22,313       1
 Cigarette COS           59,098       1
 Grocery CC Fees         1,956        1
 Roller Grill Spoilage   432          1
 TOTAL COST OF SALES     55,555

我应该怎么做?

1 个答案:

答案 0 :(得分:1)

您可以创建一个新的变量flag,在观察结果中保留其值,并在适当的时间设置/取消设置。类似的东西:

data sales2;
  set sales;
  length flag $1;
  retain flag ' ';
  if category = 'TOTAL COST OF SALES' then
    flag = ' ';
  output;
  if category = 'TOTAL SALES' then
    flag = '1';
run;