DATA Step, Macro, Functions and more

is there a way to initial the variable when append dataset

Reply
SAS Employee kwu
SAS Employee
Posts: 34

is there a way to initial the variable when append dataset

I am trying to append dataset ds1 to base. And, base has one extra variable v1 than ds1. If I just call proc append, then all obs appended to base will have a null v1. Here, I need to put a default value for v1 when appending ds1 to base.
is there a way to set a default value for v1 while appending the observations in ds1 to base rather than append to base, and then update the base for those null values of v1?
Respected Advisor
Posts: 3,777

Re: is there a way to initial the variable when append dataset

Try this....

[pre]
data class1;
set sashelp.class(obs=4);
run;
data class2;
set sashelp.class(drop=age firstobs=5);
run;
data class1;
if 0 then modify class1;
set class2;
retain age -99;
output;
run;
Proc print data=class1;
run;
[/pre]
PROC Star
Posts: 1,558

Re: is there a way to initial the variable when append dataset

That's typical case where views are useful. This will not slow down your append regardless of the size of the datasets:
[pre]
data DS1;
set SASHELP.CLASS(drop=WEIGHT);
data BASE;
set SASHELP.CLASS;
run;
 

data DS1_V/view=DS1_V;
retain WEIGHT 0;
set DS1;
run;

proc append base=BASE data=DS1_V;
run;
[/pre]

Hoping that one day the syntax:
[pre]
proc append base=BASE data=DS1 (variable= (WEIGHT length=8 value=0) );
run;
[/pre]
will be valid where the variable=() parameters use the same syntax as the attrib statement - plus the value= option - to create or modify variables for the whole datasets on the fly. The suggestion never made it to the ballot or anywhere else however.
SAS Employee kwu
SAS Employee
Posts: 34

Re: is there a way to initial the variable when append dataset

Thank you both very much indeed.

I love both suggestions. Smiley Happy It solves my problem perfectly.

thank you very much again.
Ask a Question
Discussion stats
  • 3 replies
  • 130 views
  • 0 likes
  • 3 in conversation