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

- Subscribe to 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-08-2017 06:47 AM - edited 08-08-2017 07:00 AM

Is there a way to write the 5th line below so that it works (while keeping it within a single expression / single line) ?

More generally, how can a vector be initiated by specifying formulas instead of values for each element?

```
proc iml;
x = j(3,2,.);
do i = 1 to nrow(x);
/*this doesn't work*/
x[i,] = { i 0 };
/*this does work, but it's an extra line */
x[i,1] = i;
x[i,2] = 0;
end;
quit
```

Accepted Solutions

Solution

08-08-2017
07:49 AM

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

Posted in reply to MDaniel

08-08-2017 07:33 AM

The direct answer to your question is to use the horizontal concatenation operator (||)

x[i,] = i || 0;

as described in the article "How to build a vector from expressions."

Of course, for this example, you don't need a loop at all:

```
proc iml;
x1 = T( 1:3 );
x2 = j(nrow(x1), 1, 0);
x = x1 || x2;
```

All Replies

Solution

08-08-2017
07:49 AM

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

Posted in reply to MDaniel

08-08-2017 07:33 AM

The direct answer to your question is to use the horizontal concatenation operator (||)

x[i,] = i || 0;

as described in the article "How to build a vector from expressions."

Of course, for this example, you don't need a loop at all:

```
proc iml;
x1 = T( 1:3 );
x2 = j(nrow(x1), 1, 0);
x = x1 || x2;
```