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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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