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 09-24-2014 09:45 AM
(2268 views)

Please, I wish to ask if any could help correct this error:

NOTE: Module FUNC defined.

47 interval = {A, B};

**48 call quad(answer, "Func", interval);**

** param must be numeric**

**ERROR: (execution) Character argument should be numeric**

*This is data set and code:*

Data sim;

Input A B;

cards;

1 3

2 7

3 10

4 12

;

Run;

proc iml;

use sim;

read all var{A B} into DM;

close;

A = DM[,1]; B = DM[,2];

n = nrow(DM);

start Func(x);

return( exp(2-x)#cdf("Normal", x) );

finish;

interval = {A, B};

call quad(answer, "Func", interval);

create kaplan1n var{A B Answer };

append;

quit;

1 ACCEPTED SOLUTION

Accepted Solutions

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

You want to allocate a vector outside of the loop and fill it within the loop, as described in this article: Pre-allocate arrays to improve efficiency - The DO Loop

This and other efficiency tips that you've asked about are found in Chapter 2 of *Statistical Programming with SAS/IML Software*

answer = j(nrow(A),1);

do i = 1 to nrow(A);

call quad(result, "Func", A*||B );*

answer* = result;*

end;

6 REPLIES 6

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

If you are trying to compute four integrals, use the i_th row of DM as the interval for the i_th computation:

do i = 1 to nrow(DM);

call quad(answer, func, DM[i,]);

...

end;

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

Hello Rick, My interval is A, B. The lower limit is A and upper limit is B, , the code does not specified the upper and lower limit. I have to pick the correct limit .

do i = 1 to nrow(DM);

call quad(answer, func, DM[i,]);

...

end;

I modified my code as such:

Data sim;

Input A B;

cards;

1 3

2 7

3 10

4 12

;

Run;

proc iml;

use sim;

read all var{A B} into DM;

close;

A = DM[,1]; B = DM[,2];

n = nrow(DM);

start Func(x);

return( exp(2-x)#cdf("Normal", x) );

finish;

do i = 1 to nrow(DM);

call quad(answer, "Func", DM[i,]);

end;

create kaplan1n var{A B Answer };

append;

quit;

statement : CALL at line 8281 column 1

ERROR: (execution) Matrices do not conform to the operation.

operation : QUAD at line 8307 column 1

operands : *LIT1007, _TEM1001

*LIT1007 1 row 1 col (character, size 4)

Func

_TEM1001 1 row 1 col (numeric)

3

statement : CALL at line 8307 column 1

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

Your error is that DM[1,2] is a scalar, whereas QUAD is expecting a vector with two elements, as in my code. You could also use A* || B , if you prefer.*

Of course, you also will want to accumulate the results inside the loop. Currently you are just overwriting ANSWER four times, and the data set is only writing the answer to the last integration.

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

Thanks a lot. Yes you are right,

This just give me one answer and I need a result for each row.

This code below gives me and answer. How ever, just as you said , it is not giving me the answer for each row. How do I loop it from 1 to 4 so that each row has an answer. ?

Data sim;

Input A B;

cards;

1 3

2 7

3 10

4 12

;

Run;

proc iml;

use sim;

read all var{A B} into DM;

close;

A = DM[,1]; B = DM[,2];

n = nrow(DM);

start Func(x);

return( exp(2-x)#cdf("Normal", x) );

finish;

do i = 1 to nrow(DM);

call quad(answer, "Func", A* || B ,);*

end;

create kaplan1n var{A B Answer };

append;

quit;

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

You want to allocate a vector outside of the loop and fill it within the loop, as described in this article: Pre-allocate arrays to improve efficiency - The DO Loop

This and other efficiency tips that you've asked about are found in Chapter 2 of *Statistical Programming with SAS/IML Software*

answer = j(nrow(A),1);

do i = 1 to nrow(A);

call quad(result, "Func", A*||B );*

answer* = result;*

end;

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

Data sim;

Input A B;

cards;

1 3

2 7

3 10

4 12

;

Run;

proc iml;

use sim;

read all var{A B} into DM;

close;

A = DM[,1]; B = DM[,2];

n = nrow(DM);

start Func(x);

return( exp(2-x)#cdf("Normal", x) );

finish;

answer = j(nrow(DM),1);

do i = 1 to nrow(DM);

call quad(result, "Func", A* || B ,);*

answer* = result;*

end;

create kaplan1n var{A B Answer };

append;

quit;

**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.

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.