Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 04-03-2019 10:53 AM
(717 views)

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

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

```
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;
```

--

Paige Miller

Paige Miller

5 REPLIES 5

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

```
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;
```

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I especially like the product-matrix, or is it matrix product?, it takes me back to early Computer Science programming exercises in Pascal, C, etc...

e-SAS regards,

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Tom,

Wow - something complicated made simple.

Thank you!

Jane

**Don't miss out on SAS Innovate - Register now for the FREE Livestream!**

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

Upcoming Events

- SAS Innovate | 16-Apr-2024
- From Zero to SAS: Using SAS Tasks to Summarize and Manipulate Your Data | 25-Apr-2024
- Free Webinar from Michigan SAS User Group | 25-Apr-2024
- How Can You Use Deep Learning for Personalized Pricing and Revenue Optimization? | 02-May-2024
- SAS® Enterprise Guide® Is Now Integrated With SAS® Viya® 4 | 07-May-2024
- Iowa SAS Users Group: The 14th One-Day Conference | 13-May-2024
- Nebraska SAS Users Group (NEBSUG) One-Day SAS Conference | 14-May-2024

5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.