BookmarkSubscribeRSS Feed
tmm
Fluorite | Level 6 tmm
Fluorite | Level 6


I have looked and looked and cannot find how to append just certain fields of a table. I normally append by doing this:

proc append data=base_table data=&tbl_nm  force;

> run;

But in this case I want to append only 2 fields. The base table had the same fields, label and dataset as the data I am appending.

The base table looks like this:

sys_cd         sys_desc     amount1     amount2     amount3     amount4

1                     jason            1                   1                   1                1

2                     john              2                   2                    2               2

3                     sara              3                  3                     3                3

the data table looks like this:

sys_cd            sys_desc

4                    sue

5                    michael

6                     linda

I just want to append the above to the base but because the base has amount stuff and the other does not it does not work and just does everything when I append as null values even for the sys_cd and sys_desc

6 REPLIES 6
Linlin
Lapis Lazuli | Level 10

have you tried adding option force?

Reeza
Super User

Your code is incorrect, it should be

BASE= and DATA=

not two DATA= statements.

proc append base=base_table data=&tbl_nm  force;

run;

twocanbazza
Quartz | Level 8

There is an issue in your append ie have two data's

try

data base;

infile datalines delimiter=',';

input sys_cd   sys_desc $     amount1     amount2     amount3     amount4 ;

datalines;

1,jason,1,1,1,1

2,john,2,2,2,2

3,sara,3,3,3,3

;

run;

data data;

infile datalines delimiter=',';

input sys_cd   sys_desc $     ;

datalines;

4,sue 5,michael

6,linda

;

run;

proc append base=base data=data  force; run;

umashankersaini
Quartz | Level 8

Hey...

Have you tried after correcting your codes as all suggestion above ?

You may also refer to below one for more info :Why We Use FORCE Option In PROC APPEND To Upload Data To Data Warehouse ~ SAS Certification prep and...

Regards

Uma Shanker Saini

Ksharp
Super User

Your can try:

proc append data=base_table(keep=sys_cd         sys_desc ) data=&tbl_nm(keep=sys_cd         sys_desc ) force;run;


OR


proc sql;

create table want as

select * from base_table

union all corr

select * from &tbl_nm

;

quit;


Xia Keshan

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Another method:

proc sql;

  insert into BASE_TABLE (SYS_CD,SYS_DESC)

  select  *

  from    DATA_TABLE;

quit;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 3288 views
  • 0 likes
  • 7 in conversation