Can I modify an existing SAS dataset without creating a temporary file?

Aside from the operator, modify

are there any other ways to modify the contents of SAS datasets (such as changing values ​​or adding or removing rows or columns) that do not involve creating a temporary file at work and then replacing the entire original file?

A related question: if I have one proc sql

with one statement create table

and multiple statements insert

, all targeting the same table, SAS will end up overwriting the output table multiple times at runtime or is it smart enough to do all the records in one pass? Let's assume I am not connecting to any other DBMS.

Since 2 people have already posted this message, the following answer is invalid:

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 file as soon as the data step is complete. If you interrupt such a data step, there will be an error in the log, but the original dataset will remain unchanged.

+3


source to share


4 answers


Update rows with PROC SQL; UPDATE

delete with PROC SQL; DELETE



add with PROC APPEND

orPROC SQL; INSERT

+1


source


I found one - but are there other similar methods for overwriting strings or adding / removing variables? From the operator help page append

:

The APPEND statement bypasses the processing of the original dataset and adds new observations directly to the end of the original dataset.



Find Other - It seems like the operator remove

can delete lines the way I want, but only if I use an operator modify

that I already knew about.

0


source


Original answer: Adding / removing columns or adding / removing rows can be done with a data step.

The drop statement removes original_variable_A from the dataset. The line "new_variable = 25;" adds a new variable to the dataset. The do loop adds new lines. The where clause removes any rows that do not meet the specified condition.

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 might be confusion about the meaning of "temporary file". If by temporary file you mean a dataset in the working directory, my initial answer will suffice. However, if you mean the standard SAS dataset creation for persistent files as described in your comment ... I think you can do some manipulation of proc datasets on views, which certainly won't create temporary files. https://support.sas.com/rnd/base/Tipsheet_DATASETS.pdf

-1


source


Yes. Let's say if I have a dataset at location "C: \ Temp" that contains customer addresses called customer_addr. All you have to do is link to the same library and dataset in the data step, and it will overwrite the existing dataset instead of putting it in the working library.

libname Customers 'C:\Temp';
data Customers.customer_addr;
set Customers.customer_addr;
*do some logic here to remove or filter rows/columns;
run;

      

-1


source







All Articles