[英]Can I modify an existing SAS dataset without creating a temporary file?
Apart from the modify
statement, are there any other ways of modifying the contents of SAS datasets (ie altering values, or adding or removing rows or columns) that don't involve creating a temporary file in work and then replacing the entire original file? 除了
modify
语句之外,还有其他方法可以修改SAS数据集的内容(即更改值,添加或删除行或列), 这些方法不涉及在工作中创建临时文件,然后替换整个原始文件?
Related question: if I have a single proc sql
with one create table
statement and several insert
statements, all targeting the same table, will SAS end up overwriting the output table several times during execution, or is it clever enough to do all the writes in one pass? 相关问题:如果我有一个带有一个
create table
语句和几个insert
语句的proc sql
,都是针对同一个表的,那么SAS会在执行期间多次覆盖输出表,或者它是否足够聪明以完成所有写入操作一通? Let's assume that I'm not connecting to any other DBMS. 我们假设我没有连接到任何其他DBMS。
Since 2 people have posted this already, the following is not a valid answer: 由于已经有2人发布了这个,以下不是一个有效的答案:
data lib.dsn;
set lib.dsn;
/*Insert logic here*/
run;
If you do this, SAS creates a temporary file and replaces the original lib.dsn once the data step is complete. 如果执行此操作,SAS将创建一个临时文件,并在数据步骤完成后替换原始lib.dsn。 If you interrupt this kind of data step, there will be an error in the log, but the original dataset will remain unchanged.
如果中断此类数据步骤,则日志中将出现错误,但原始数据集将保持不变。
Update rows with PROC SQL; UPDATE
使用
PROC SQL; UPDATE
更新行PROC SQL; UPDATE
PROC SQL; UPDATE
delete with PROC SQL; DELETE
用
PROC SQL; DELETE
删除PROC SQL; DELETE
PROC SQL; DELETE
add with PROC APPEND
or PROC SQL; INSERT
添加
PROC APPEND
或PROC SQL; INSERT
PROC SQL; INSERT
I found one - but are there other similar methods for overwriting rows, or adding/removing variables? 我发现了一个 - 但是有其他类似的方法可以覆盖行,或者添加/删除变量吗? From the help page for the
append
statement: 从
append
语句的帮助页面:
The APPEND statement bypasses the processing of data in the original data set and adds new observations directly to the end of the original data set.
APPEND语句绕过原始数据集中的数据处理,并将新的观察结果直接添加到原始数据集的末尾。
Found another - it seems that the remove
statement can delete rows in the way I want to, but only if I'm using a modify
statement, which I already knew about. 发现另一个 - 似乎
remove
语句可以按照我想要的方式删除行,但前提是我正在使用我已经知道的modify
语句。
Original Answer: Adding/removing columns or adding/removing rows can all be done with a data step. 原始答案:添加/删除列或添加/删除行都可以通过数据步骤完成。
The drop statement removes the variable original_variable_A from the dataset. drop语句从数据集中删除变量original_variable_A。 The line "new_variable = 25;"
行“new_variable = 25;” adds a new variable to the dataset.
向数据集添加新变量。 The do loop adds new rows.
do循环添加新行。 The where clause removes any rows not satisfying the condition outlined.
where子句删除任何不满足条件的行。
data libname.permanent_data;
set libname.permanent_data;
drop original_variable_A;
new_variable = 25;
do i = 1 to 2;
original_variable_B = 3;
new_variable = 2;
output;
end;
where original_variable_B <= 50;
run;
Revised Answer: I think there may be come confusion in the meaning of "temporary file". 修订回答:我认为“临时档案”的含义可能会引起混淆。 If by temporary file you mean dataset in work directory, my original answer will suffice.
如果通过临时文件表示工作目录中的数据集,我的原始答案就足够了。 However, if you mean the standard SAS dataset creation of permanent files as explained in your comment... I think you can do some manipulation with proc datasets on views that will certainly not create the temp files.
但是,如果您的意思是标准SAS数据集创建永久文件,如评论中所述......我认为您可以对视图上的proc数据集进行一些操作,这些操作肯定不会创建临时文件。 https://support.sas.com/rnd/base/Tipsheet_DATASETS.pdf
https://support.sas.com/rnd/base/Tipsheet_DATASETS.pdf
Yes. 是。 Say if I have a dataset in the location 'C:\\Temp' that contains customer addresses called customer_addr.
假设我在“C:\\ Temp”位置有一个数据集,其中包含名为customer_addr的客户地址。 All you have to do is reference the same library and dataset in the data step and it will overwrite the existing dataset instead of putting it to the Work library.
您所要做的就是在数据步骤中引用相同的库和数据集,它将覆盖现有数据集,而不是将其放入工作库。
libname Customers 'C:\Temp';
data Customers.customer_addr;
set Customers.customer_addr;
*do some logic here to remove or filter rows/columns;
run;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.