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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 776 views
  • 0 likes
  • 3 in conversation