BookmarkSubscribeRSS Feed
tommy81
Obsidian | Level 7
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 .
3 REPLIES 3
Patrick
Opal | Level 21
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
ariari
Calcite | Level 5
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
Ksharp
Super User
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

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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