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-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!

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