turn on suggestions

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

Showing results for

Find a Community

Topic Options

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-14-2013 08:42 PM

It is fine to define the following scalars in SAS:

x1=1/sqrt(5);

x2=2/5;

x3=6**3;

however, syntax errors appear when one tries to define a vector like this:

proc iml;

x={1/sqrt(5) 2/5 6**3};

I never experienced a similar problem in Matlab which I use more frequently than SAS.

It seems that there is a similar problem in SAS data step as well. I know that probably one rarely has to use arithmetic operators in defining

a matrix or in data steps. But I am curious whether this is an easy solution for this.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to humenghu

08-15-2013 01:19 AM

For** iml** (not im**s**) SAS/IML(R) 12.3 User's Guide ( Multiplication Operator, Elementwise: # ) a sample working with vectors

For the datastep SAS(R) 9.4 Language Reference: Concepts (Syntax for Defining and Referencing an Array)

The major problem looks not to be technical, but getting the syntax and words aligned from one product to another.

---->-- ja karman --<-----

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to jakarman

08-15-2013 09:45 AM

Thanks for your reply. After reading the materials, I still have not found a way to solve this particular problem using matrix multiplication. I might try it again later.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to humenghu

08-15-2013 03:38 AM

Hi there, Fellow MATLAB user!

If you would like to define an array use the following syntax:

data test;

/* define array*/

array x{3};

/*populate array values*/

x{1}=1/sqrt(5);

x{2}=2/5;

x{3}=6**3;

run;

/* the resultant fields 'x1, x2, x3' remain in the dataset, however the array structure exists only in the data step, unless reassigned */

data test2;

set test;

/* reconnect x1 x2 and x3 to an array reference*/

array x{3};

/* manipulate array*/

arithmetic = x{2}+x{1}+x{3};

run;

proc print data=test2;

run;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Murray_Court

08-15-2013 09:49 AM

Thank you for providing this example.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Murray_Court

08-15-2013 10:12 AM

Here is my example which would be much easier to accomplish in Matlab:

proc iml;

/* an example of diagonalizing a symmetric matrix A*/

/* A wrong attempt to define an orthogonal matrix X*/

*X={-1/3 2/sqrt(5) -2/(3*sqrt(5)), -2/3 0 5/(3*sqrt(5)), 2/3 1/sqrt(5) 4/(3*sqrt(5))} ;

/*define an orthogonal matrix X using concatenations*/

X=(-1/3 || 2/sqrt(5) || -2/(3*sqrt(5))) // (-2/3 || 0 || 5/(3*sqrt(5))) // ( 2/3 || 1/sqrt(5) || 4/(3*sqrt(5)));

A={2 2 -2, 2 5 -4, -2 -4 5};

print A " " X [format=5.3];

print (X`*X) [format=5.3] [label='X´*X'];

print (eigval(A)) [format=5.3] [label='eigenvalues of A'];

print (X`*A*X) [format=5.3] [label='X´*A*X'];

quit;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to humenghu

08-15-2013 05:26 AM

Welcome to the SAS/IML language. There are many former MATLAB users on this Support Community, including myself.

To answer your question, curly braces are used to construct a matrix from LITERAL numbers. To build a matrix from EXPRESSIONS, use the horizontal concatenation operator (||) or the vertical concatenation operator, as described in this article:

How to build a vector from expressions - The DO Loop

For your particular example, use

x = (1/sqrt(5)) || (2/5) || (6**3);

You might also enjoy reading about tips to convert a MATLAB program to SAS/IML: Translating a MATLAB program into the SAS/IML language: A case study - The DO Loop The article includes a very basic MATLAB to IML cheatsheet that might be helpful to you.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

08-15-2013 09:58 AM

Thanks for the tips which are exactly right for my problem. I am happy to learn that there are many Matlab users here in the community.