数据步骤操作基于两个字段调节

时间:2016-07-21 03:51:08

标签: sas

对于数据集,

// ==UserScript==
// @name       FBA Calculator Test
// @namespace  http://use.i.E.your.homepage/
// @version    0.1
// @description  enter something useful
// @match        https://sellercentral.amazon.com/fba/profitabilitycalculator/index?lang=en_US
// @require  https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js

// @copyright  2012+, You

// ==/UserScript==
$(document).ready(function(){

    if($("#search-string").val() == "Enter your product name, UPC, EAN, ISBN, or ASIN") {
        $("#search-string").val("B017C1Q7TM");
        $("input.a-button-input[type='submit']").eq(0).click();
    }

});

期望输出,

data testing;
    input key $ output $;
    datalines;
1 A
1 B
1 C
2 A
2 B
2 C
3 A
3 B
3 C
;
run;

逻辑是如果键或输出出现在列之前,则删除观察。

1 A 
2 B
3 C

我的努力:

1 个答案:

答案 0 :(得分:1)

这里的基本想法是你保留一份已经使用过的字典,并搜索一下。这是一个简单的基于数组的方法;一个哈希表可能会更好,当然更少的内存密集,而且可能更快 - 我会把它留给你的想象力。

data want;
  set testing;
  array _keys[30000] _temporary_;      *temporary arrays to store 'used' values;
  array _outputs[30000] $  _temporary_;
  retain _keysCounter 1 _outputsCounter 1;  *counters to help us store the values;
  if whichn(key, of _keys[*]) = 0 and whichc(output,of _outputs[*]) = 0 /* whichn and whichc search lists (or arrays) for a value.  */
    then do;
      _keys[_keysCounter] = key;            *store the key in the next spot in the dictionary;
      _keysCounter+1;     *increment its counter;
      _outputs[_outputsCounter] = output;   *store the output in the next spot in the dictionary;
      _outputsCounter+1;  *increment its counter;
      output;             *output the actual datarow;
  end;
  keep key output;
run;