BookmarkSubscribeRSS Feed
sassharp
Calcite | Level 5

need to save sas data set in database by using libname. at the starting of each month need to delete only( said only) rows with out deleting table structure and update the table with new data.

any ideas?

6 REPLIES 6
Haikuo
Onyx | Level 15

More detail will definitely help.  For now, it seems to me that 'update' statement using with datastep or SQL may be relevant.

Haikuo

sassharp
Calcite | Level 5

proc sql; delete from import.x; quit;

data import.x;

set export.y;

run;

import and export are libnames defined correctly on oracle, sas side respectively.

Q) Need to delete all rows in x and fill rows with y .

LinusH
Tourmaline | Level 20

The data step replaces the RDBMS table, so in your example the delete operation is unnecessary.

If you want the table to be persistant, use delete, then SQL insert (or proc append).

Also, there are perhaps more efficient truncation command for your RDBMS that can be executed in SQL pass-thru.

Data never sleeps
sassharp
Calcite | Level 5

I do know sql pass thru. Here I wanted to delete all previous months data then load the RDBMS table with present month data(from SAS). once I use proc delete whole RDBMS table is deleting. Just I wanted to delete rows only. not table structure.

sassharp
Calcite | Level 5

proc sql;

  connect to sqlsvr(dsn=xxx user=yyy pwd='zzz');

  execute (truncate table base.monthlydata) by sqlsvr;

  disconnect from sqlsvr;

  quit;

error in log

ERROR: CLI execute error: [DataDirect][ODBC SQL Server Driver][SQL Server]Cannot find the object "monthlydata" because it does not

       exist or you do not have permissions.

Ksharp
Super User

Just as LinusH said in your example the delete operation is unnecessary if the final table name is the same with old table.

data class;
 set sashelp.class;
run;
proc sql;
 delete * from class;

 insert into  class
  select * from sashelp.class;
quit;

Ksharp

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1670 views
  • 0 likes
  • 4 in conversation