英文:
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;
然而,您可以通过创建一个分类变量,在WHERE
或BY
语句中稍后使用,这样会更为方便。
英文:
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;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论