SAS - 根据表中的另一个变量值反转变量值的顺序 [英] SAS - Reverse order of values of a Variable based on another Variable value in a Table

查看:49
本文介绍了SAS - 根据表中的另一个变量值反转变量值的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总而言之,我正在将文档的句子解析为单个句子.我需要这个是为了更大的事业.

To summarize, I am working on parsing sentences of documents into single sentences. I need this for a bigger cause.

我有一个表Position",它为我提供了文档 ID (ID) 和该文档中某个句子的句子编号 (NUM).我还有一列显示解析的句子(SENTENCE).

What I have is a table 'Position' which gives me the document id (ID) and the sentence number of a sentence in that document (NUM). I also have a column to display the sentence parsed (SENTENCE).

所以一个示例表是:

ID NUM SENTENCE
1   3    Hello
1   2    How are you
1   1    Fine
2   2    Thank you
2   1    You're Welcome
3   1    Nice Weather

这意味着文档 1 中识别出三个句子,文档 2 中识别出两个等等.

What this means is that there were three sentences identified in document 1, two in document 2 and so on.

问题是(ID, NUM) = (1,3) or "Hello",指的是文档1中的第三句,而(ID, NUM) = (1, 1) or "Fine",指的是到文档 1 中的第一句话,这也是所有其他文档的模式继续的方式.

The problem is that (ID, NUM) = (1,3) or "Hello", refers to the third sentence in document 1, and (ID, NUM) = (1, 1) or "Fine", refers to the first sentence in document 1,and that's how the pattern continues for all other documents as well.

我想颠倒每个 ID NUM 的顺序,以使句子顺序更加清晰.这也是输入我程序的其他部分所必需的.

I'd like to reverse the order of NUM per ID, to give better clarity of the sentence order. This is also needed for feeding into other parts of my program.

基本上,我希望我的输出表看起来像:

Essentially, I'd like my output table to look like:

ID NUM SENTENCE
1   1    Hello
1   2    How are you
1   3    Fine
2   1    Thank you
2   2    You're Welcome
3   1    Nice Weather

我将不胜感激任何有关如何执行此操作的帮助.

I would greatly appreciate any assistance on how to perform this.

我想更改输出以反映输出表中句子编号的互换.句子的顺序将保持不变.这就是你好"将被表示为句子 1,而不是 3.

I would like to change the output to reflect the interchanging of sentence numbers in the output table. The order of the sentences would remain the same. This is so 'Hello' would be represented as sentence 1, as opposed to 3.

因此,我只希望在输出表中的每个ID"变量值中交换NUM"变量.

So hence, I would like only the 'NUM' variable interchanged within each 'ID' variable value in the output table.

推荐答案

proc sort data=position;
  by ID NUM;
run;

我想我误解了这个问题.你真正想要的是:

I think I misunderstood the question. What you really want is:

proc sort data=position;
  by ID descending NUM;
run;

data want (rename=(new_NUM=NUM));
  set position (drop=NUM);
  by ID;
  if first.ID then new_NUM = 1;
  output;
  new_NUM + 1;
run;

这篇关于SAS - 根据表中的另一个变量值反转变量值的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆