SAS - 排除前几行

时间:2016-02-05 19:13:42

标签: sas

我有一组数据如下。 我需要排除第一行&#39;计算&lt; 100&#39;基于MODEL。一旦计数> 100,无论计数如何,都将保留以下行。 100或<100。

|Make |Model   |SoldMonth|Counts|
|ford |class_c |Jan_2015 |80    |
|ford |class_c |Feb_2015 |90    |
|ford |class_c |Mar_2015 |70    |
|ford |class_c |Apr_2015 |120   |
|ford |class_c |May_2015 |130   |
|ford |class_c |Jun_2015 |50    |
|ford |class_c |Jul_2015 |70    |
|ford |class_c |Aug_2015 |140   |
|ford |class_c |Sep_2015 |110   |   
|ford |Maxi    |Jan_2015 |20    |
|ford |Maxi    |Feb_2015 |50    |  
|ford |Maxi    |Mar_2015 |80    |
|ford |Maxi    |Apr_2015 |120   |    
|ford |Maxi    |May_2015 |130   |
|ford |Maxi    |Jun_2015 |110   |   
|ford |Maxi    |Jul_2015 |180   |
|ford |Maxi    |Aug_2015 |90    |
|ford |Maxi    |Sep_2015 |110   |

这是我想要的:

|Make |Model   |SoldMonth |Counts|    
|ford |class_c |Apr_2015  |120   |
|ford |class_c |May_2015  |130   |
|ford |class_c |Jun_2015  |50    |
|ford |class_c |Jul_2015  |70    |
|ford |class_c |Aug_2015  |140   |
|ford |class_c |Sep_2015  |110   |    
|ford |Maxi    |Apr_2015  |120   |  
|ford |Maxi    |May_2015  |130   |
|ford |Maxi    |Jun_2015  |110   |   
|ford |Maxi    |Jul_2015  |180   |
|ford |Maxi    |Aug_2015  |90    |
|ford |Maxi    |Sep_2015  |110   |

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:5)

您可以创建在找到第一个GE 100时设置的标志,并使用它来确定要输出的观察值。

data ford;
   input (a b c)($) y;
   cards;
ford class_c Jan_2015 80
ford class_c Feb_2015 90
ford class_c Mar_2015 70
ford class_c Apr_2015 120
ford class_c May_2015 130
ford class_c Jun_2015 50
ford class_c Jul_2015 70
ford class_c Aug_2015 140
ford class_c Sep_2015 110
ford Maxi Jan_2015 20
ford Maxi Feb_2015 50
ford Maxi Mar_2015 80
ford Maxi Apr_2015 120
ford Maxi May_2015 130
ford Maxi Jun_2015 110
ford Maxi Jul_2015 180
ford Maxi Aug_2015 90
ford Maxi Sep_2015 110
;;;;
   run;
proc print;
   run;
data ford2;
   set ford;
   by a b notsorted;
   if first.b then f=0;
   if not f and y lt 100 then f+0;
   else f=1;
   if f;
   run; 
proc print;
   run;

enter image description here