BookmarkSubscribeRSS Feed
raveena
Obsidian | Level 7

Hi ,

I have two tables Table 1 and Table 2,
need to rollup from table 1 Covunit field value to Table 2  totunits field where rev=N

Table 1:

In table 1, we have ID that has multiple line no.

ID LINENO pos covunit rev
1   1     23    1     N
1   2     23    1     N
1   3     23    1     N
1   4     23    1     N


2   1     23    1     N
2   2     23    1     N


3   3     23    1     N


4   5     23    1     Y


Table 2:

In table 2, the default value for lines is 0.

ID lineNo totunits
1   0   
2   0
3   0
4   0


Output should be:

ID lineno Totunits
1   0      4
2   0      2
3   0      1
4   0

Please help me out on this logic.

Thanks in Advance

2 REPLIES 2
art297
Opal | Level 21

There are a number of ways to do what you want.  The following assumes that table2 is sorted in ID order:

proc freq data=table1 (where=(rev eq 'N'));

  tables id*rev/out=sums (keep=ID count

         rename=(count=totunits));

run;

data table3;

  merge table2 sums;

  by id;

run;

MikeZdeb
Rhodochrosite | Level 12

Hi ... another idea ...

proc sql;

create table t3 as

select id, lineno, totunits from

(select id as xid , sum(covunit) as totunits from t1 (where=(rev eq 'N')) group xid) right join t2

on xid eq id;

quit;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1395 views
  • 0 likes
  • 3 in conversation