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

09-08-2010 09:55 PM

hello all,

how can I augment a vector or matrix with proc iml?

for example, lets say i have a vector x={1,2} and I want to augment x to a 4x1 vector with missing value indictor (.) in positions 2 and 3. in other words i want x=(1, . , . , 2}. is this possible to do??

pretty much i have an x vector and i also have an index vector (i={2,3} in this example) with the positions i want to include the (.) character.

how can I augment a vector or matrix with proc iml?

for example, lets say i have a vector x={1,2} and I want to augment x to a 4x1 vector with missing value indictor (.) in positions 2 and 3. in other words i want x=(1, . , . , 2}. is this possible to do??

pretty much i have an x vector and i also have an index vector (i={2,3} in this example) with the positions i want to include the (.) character.

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

Posted in reply to trekvana

09-09-2010 06:17 AM

The easiest way is to allocate a matrix of missing values and then fill in the nonmissing values by using subscripts. Suppose your data look like this:

N = 4; /** number of rows after including missing values **/

MissingIdx = {2, 3}; /** indices of rows that contain missing **/

x = {1,2}; /** data values **/

The hard part is that you need to know the indices of the NONmissing observations, which you can find by using the SETDIF function. The function is explained at

http://support.sas.com/documentation/cdl/en/imlug/59656/HTML/default/langref_sect241.htm

NMidx = setdif(1:N, MissingIdx); /** find the indices for nonmissing values **/

newX = repeat(., N); /** create answer vector with all missings **/

newX[NMidx] = x; /** assign nonmissing values in the specified locations **/

print newX;

N = 4; /** number of rows after including missing values **/

MissingIdx = {2, 3}; /** indices of rows that contain missing **/

x = {1,2}; /** data values **/

The hard part is that you need to know the indices of the NONmissing observations, which you can find by using the SETDIF function. The function is explained at

http://support.sas.com/documentation/cdl/en/imlug/59656/HTML/default/langref_sect241.htm

NMidx = setdif(1:N, MissingIdx); /** find the indices for nonmissing values **/

newX = repeat(., N); /** create answer vector with all missings **/

newX[NMidx] = x; /** assign nonmissing values in the specified locations **/

print newX;

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

Posted in reply to Rick_SAS

09-09-2010 12:37 PM

Thanks Rick!