01-09-2014 12:35 PM
Dear SAS community,
I would like to add a SAS dataset to an existing SQL Server table. I would like to add the SAS dateset "adding" to the sql table "have." I have been using the below code.
proc append base=SQLSERVER.have data=WORK.adding;
However, when I run the code, I receive this error.
NOTE: Appending WORK.adding to SQLSERVER.have.
WARNING: Variable X1 was not found on DATA file.
WARNING: Variable X2 was not found on DATA file.
WARNING: Variable X3 was not found on DATA file.
NOTE: There were 1 observations read from the data set WORK.adding.
NOTE: 0 observations added.
NOTE: The data set SQLSERVER.have has . observations and 44 variables.
ERROR: CLI execute error: [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert explicit
value for identity column in table 'have' when IDENTITY_INSERT is set to OFF.
NOTE: Statements not processed because of errors oted above.
I believe the errors are a result of two reasons.
1) I have variables (i.e. variables X1, X2, X3) in the SQL table that are not in the SAS dataset
2) I have one variable (i.e. variable X4) in the SQL table that is in a different format as that same variable in the SAS dataset
Is there a way to force the append without adding variables to the SAS dataset? And without changing the format of the variable shared by both sources?
01-09-2014 01:34 PM
Since you have an identity column in sql you need to specify the columns that you're inserting into:
insert into have (
01-09-2014 04:31 PM
When I try this method, I receive any error that says "ERROR: Attempt to insert fewer columns than specified after the insert table name. What do you advise? My base table 'Have' does have more variables than my SAS dataset "want". I would like to keep it that way, so how to amend the SQL insert code to reflect the following scenario . . .
insert into have (
01-09-2014 04:54 PM
You have to manually match up the columns in the two clauses. You shouldn't include the identity column but only those that you have in your sas table. I may have the table names reversed...but it sounds like you're inserting into the sql table and selecting from the sas dataset.
insert into sqllibname.sqltable (
columns that match the sas dataset
column names in the same order as above
01-10-2014 03:58 AM
I believe the FORCE option only manages the cases where you're having variables in source not existing in target. What you need is to have all target columns in source. This could be done via an additional mapping step, eg:
set base.data(obs=0) work.data;
proc append base=base.data