How to move specific rows from an original table to a new table?

huangapple go评论52阅读模式
英文:

How to move specific rows from an original table to a new table?

问题

在SAS中,我有一个包含1000行的表格。我尝试将该表格分成两个表格。将第1行到第500行放入表A,将第501行到第1000行放入表B。请问有哪段代码可以实现这个功能?非常感谢大家的帮助!

我正在在线搜索代码,但在谷歌上找不到任何信息,感激不尽。

英文:

In SAS, I have a table that have 1000 rows. I am trying to separate that table into two tables. Row1-500 to Table A and row501-100 to table B. What is the code that can do this function. Thank you all for helping!

I am searching the code online and cannot get anything on google, help is appreciated.

答案1

得分: 2

数据语句列出了步骤的输出表。OUTPUT语句明确将一行发送到每个输出表中。显式的OUTPUT <目标> ... <目标-k>语句仅将记录发送到指定的表中。当使用SET读取单个数据集时,自动隐式循环索引变量_n_可以作为行计数器。

尝试

data want1 want2;
  set have;
  if _n_ <= 500 then output want1; else output want2;
run;

然而,您可以通过创建一个分类变量,在WHEREBY语句中稍后使用,这样会更为方便。

英文:

The DATA statement lists the output tables of the step. An OUTPUT statement explicitly sends a row to each of the output tables. An explicit OUTPUT <target> ... <target-k> statement sends records to the specified tables only. The automatic implicit loop index variable _n_ can act as a row counter when a single data set is being read with SET.

Try

data want1 want2;
  set have;
  if _n_ <= 500 then output want1; else output want2;
run;

However, you may be better served by creating a categorical variable that can be used later in WHERE or BY statements.

答案2

得分: 0

也许设置选项会有所帮助。尝试使用 firstobs=obs= 来选择所需的行。以下是如何使用它们的示例:

data want1;
  set have(obs=500);
run;

data want2;
  set have(firstobs=501 obs=1000);
run;
英文:

Maybe the set options will help.Try firstobs= and obs= to choose the rows you want.
Here is how to use them:

data want1;
  set have(obs=500);
run;
data want2;
  set have(firstobs=501 obs=1000);
run;

huangapple
  • 本文由 发表于 2023年2月14日 01:59:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75439602.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定