Help using Base SAS procedures

keep statement in Proc Append

Reply
Occasional Contributor
Posts: 18

keep statement in Proc Append

 

proc append base=work.Empty data=task.&provider ( keep = USERID provider qry RunDate); run; 

I am getting following error if I use the keep statement in the Proc append statement as 

 

 

ERROR: The variable USERID in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable provider in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable qry in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable Rundate in the DROP, KEEP, or RENAME list has never been referenced.

 

Work.Empty is an empty data set and does not have anything inside it. I tried to look up the syntax for keep statement in PROC Append, but no use. The error is because of the syntax? 

 

If I use a dataset with keep statement, like the following code. It is working.

 

data Prov_new (keep =USERID providerPPN qryname Rundate);
set task.&provider ;
run;
proc append force data= Prov_new base=work.empty;
run;

I want to reduce those 2 lines of code and at the same trying to figure out the issue. Please help.

Super User
Posts: 23,683

Re: keep statement in Proc Append

[ Edited ]

You have some other issue, your append works fine for me. Are you sure Empty doesn't exist?

Are you sure that all those variables are in your dataset already?

 

1223 proc append base=work.Empty data=sashelp.class ( keep = Name
1223! Age); run;

NOTE: Appending SASHELP.CLASS to WORK.EMPTY.
NOTE: BASE data set does not exist.
DATA file is being copied to BASE file.
NOTE: There were 19 observations read from the data set
SASHELP.CLASS.
NOTE: The data set WORK.EMPTY has 19 observations and 2 variables.
NOTE: PROCEDURE APPEND used (Total process time):
real time 0.12 seconds
cpu time 0.00 seconds

 

 


UPEN wrote:

 

proc append base=work.Empty data=task.&provider ( keep = USERID provider qry RunDate); run; 

I am getting following error if I use the keep statement in the Proc append statement as 

 

 

ERROR: The variable USERID in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable provider in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable qry in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable Rundate in the DROP, KEEP, or RENAME list has never been referenced.

 

Work.Empty is an empty data set and does not have anything inside it. I tried to look up the syntax for keep statement in PROC Append, but no use. The error is because of the syntax? 

 

If I use a dataset with keep statement, like the following code. It is working.

 

data Prov_new (keep =USERID providerPPN qryname Rundate);
set task.&provider ;
run;
proc append force data= Prov_new base=work.empty;
run;

I want to reduce those 2 lines of code and at the same trying to figure out the issue. Please help.


 

Super User
Posts: 13,508

Re: keep statement in Proc Append

Your statement "Work.Empty is an empty data set and does not have anything inside it. " explains the error. If there are no variables then there is nothing to "keep" and attempting to do so generates an error.

 

Since Proc Append will not let you add any variables that are not in the base set then the keep option isn't really needed. If you want to avoid the problem of SAS not wanting to add the data when you do have varaibles not in the base set then use the FORCE option. Note the force options will not add those variables but will allow the appending of varaibles that do match the base data. If you use the force option because you know there are variables you do not want to add to the base set you might want to include the NOWARN option as well to prevent the warning SAS will put in the log that the Force option was used.

 

Also not that if you have variables of different types but same name the ones in the append set will be missing in the result. There is not conversion. And different lengths for the same variable may result in trucation.

 

 

Ask a Question
Discussion stats
  • 2 replies
  • 591 views
  • 0 likes
  • 3 in conversation