## Populating values cell by cell

Frequent Contributor
Posts: 83

# Populating values cell by cell

Hi ,

Please could somebody thow light on the following situation.

Have 2 tables say T1 and T2 .

I need to populate another table T3 of the same dimension as the above.

For example I need the values of (1,1) in T3 to be the
ratio of values in T1 (1,1) / T2(1,1)

i.e T3(1,1)=T1 (1,1) / T2(1,1)
T3(1,2)=T1 (1,2) / T2(1,2) etc...

Help would be greatly appreciated .
Posts: 4,736

## Re: Populating values cell by cell

Hi Tommy

You might want to do some reading of how SAS works. There are a few good SAS books in the market as well as the SAS Online Doc (the SAS Concepts would be a start).

Have a look at below code. May be this will answer your question.

data t1;
input id t1_value;
datalines;
1 10
2 55
3 8
;
run;

data t2;
input id t2_value;
datalines;
1 2
2 5
4 100
;
run;

data t3;
merge t1 t2;
by id;
if t2_value ne 0 then
t3_value=t1_value/t2_value;
run;

proc print data=t3;
run;

HTH
Patrick
Occasional Contributor
Posts: 7

## Re: Populating values cell by cell

Hi Tommy

Pls, see solution of your problem.

data t1 ;
input id a b c ;
cards;
1 4 5 8
2 8 3 1
3 6 2 11
;
run;

data t2 ;
input id a b c ;
cards;
1 14 35 48
2 28 3 41
3 16 42 11
;
run;

proc SQL ;
create table t3 AS
select t1.id as id, t1.a/t2.a format=8.5 AS a , t1.b/t2.b AS b , t1.c/t2.c AS c
from t1 as t1, t2 as t2
where t1.id=t2.id ;
quit ;
run ;

good luck
Irena
Super User
Posts: 10,784

## Re: Populating values cell by cell

Do these two dataset (T1 T2) have the same names?
if has the same name ,you need to rename them.
[pre]
proc sql feedback;
select name from dictionary.columns where libname=upcase("&libname") and memname=upcase("&right_dsn");
select name
into : name1 - : name&sqlobs.
from dictionary.columns where libname=upcase("&libname") and memname=upcase("&right_dsn");
quit;
proc datasets library=&libname memtype=data nolist;
modify &right_dsn;
rename %do i=1 %to &sqlobs;
&&name&i = _&&name&i
%end;
;
quit;
[/pre]

If not ,can make a merge by variable by using 'count+1';

[pre]
data t1;
input ....
count+1;
run;
data t2;
input ....
count+1;
run;

data T3;
merge T1 T2;
by count;
....;
run;

[/pre]

Ksharp
Discussion stats
• 3 replies
• 237 views
• 0 likes
• 4 in conversation