Version 9.4 with no access to library SAS/STATS or IML
The following source code is a condensed version of 2 datasets. Actual data is longer with several decimal places of accuracy.
data work.have1;
input a b c;
datalines;
5 6 7
8 9 4
3 2 3
;
run;
data work.have2;
input a b c;
datalines;
4 5 6
2 3 4
9 7 2
;
run;
Desired output is product of corresponding elements:
a b c
20 30 42
16 27 16
27 14 6
The following is the first attempt at coding. It compiles without errors, but contains 6 rows and 3 columns whereas the datasets are appended to one another:
proc sql;
create table work.product1 as
select * from work.have1
outer union corr
select * from work.have2;
quit;
The following is the second attempt at coding. It compiles without errors, but does not produce the desired results:
proc fcmp;
array h1[3,3] /nosymbols;
array h2[3,3] /nosymbols;
array product[3,3] ;
re=read_array('work.have1',h1);
re=read_array('work.have2',h2);
call mult(h1,h2,product);
rc=write_array('work.product',product);
run;
Thank you in advance for your support, insight, and willingness to assist.
Sincerely,
Jane
data work.have1;
input a1 b1 c1;
datalines;
5 6 7
8 9 4
3 2 3
;
run;
data work.have2;
input a2 b2 c2;
datalines;
4 5 6
2 3 4
9 7 2
;
run;
data want;
merge have1 have2;
result_a=a1*a2;
result_b=b1*b2;
result_c=c1*c2;
keep result:;
run;
data work.have1;
input a1 b1 c1;
datalines;
5 6 7
8 9 4
3 2 3
;
run;
data work.have2;
input a2 b2 c2;
datalines;
4 5 6
2 3 4
9 7 2
;
run;
data want;
merge have1 have2;
result_a=a1*a2;
result_b=b1*b2;
result_c=c1*c2;
keep result:;
run;
Thank you for the feedback.
Looks like it will be necessary to create additional variable (column) names.
No worries, I can do that.
Cheers!
Jane
Assuming that both HAVE1 and HAVE2 have exactly the same variables then here is method that will work without having to know the names of the variables.
Use a temporary array to hold the values for the first dataset.
Just make sure to make the temporary array as large or larger than the number of variables.
data want ;
set have1;
array x _numeric_;
array y [1000] _temporary_;
do _n_=1 to dim(x);
y[_n_]=x[_n_];
end;
set have2;
do _n_=1 to dim(x);
x[_n_]=y[_n_]*x[_n_];
end;
run;
Tom,
Wow - something complicated made simple.
Thank you!
Jane
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.