BookmarkSubscribeRSS Feed
kwu
SAS Employee kwu
SAS Employee
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?
3 REPLIES 3
data_null__
Jade | Level 19
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]
ChrisNZ
Tourmaline | Level 20
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.
kwu
SAS Employee kwu
SAS Employee
Thank you both very much indeed.

I love both suggestions. 🙂 It solves my problem perfectly.

thank you very much again.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 1102 views
  • 0 likes
  • 3 in conversation