Statistical programming, matrix languages, and more

Creating data set from specific columns in other data set iml

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Creating data set from specific columns in other data set iml

I have a data set with a number of columns. I am wanting to create a data set from this using a selection of the columns:

 

In iml

 

Instead of

use = old_use[1:100, 1:75];

 

I want to have

use = old_use[1:100, 1:50] + old_use[1:100, 53:57] + old_use[1:100, 59:75];

 

But it is not returning the correct number of columns....


Accepted Solutions
Solution
‎03-09-2017 10:19 AM
SAS Super FREQ
Posts: 4,171

Re: Creating data set from specific columns in other data set iml

Posted in reply to newSAS2017

The addition operator is trying to add matrices that do not have the same number of columns. Perhaps you mean to use the concatenation operator:

 

use = old_use[1:100, 1:50] || old_use[1:100, 53:57] || old_use[1:100, 59:75];

 

If so, a more efficient method is to form a vector of the column indices and then do a single extraction:

 

cols = (1:50) || (53:57) || (59:75);

use = old_use[1:100, cols];

View solution in original post


All Replies
Solution
‎03-09-2017 10:19 AM
SAS Super FREQ
Posts: 4,171

Re: Creating data set from specific columns in other data set iml

Posted in reply to newSAS2017

The addition operator is trying to add matrices that do not have the same number of columns. Perhaps you mean to use the concatenation operator:

 

use = old_use[1:100, 1:50] || old_use[1:100, 53:57] || old_use[1:100, 59:75];

 

If so, a more efficient method is to form a vector of the column indices and then do a single extraction:

 

cols = (1:50) || (53:57) || (59:75);

use = old_use[1:100, cols];

Occasional Contributor
Posts: 8

Re: Creating data set from specific columns in other data set iml

Thank you that works really well!

 

Super User
Posts: 9,869

Re: Creating data set from specific columns in other data set iml

Posted in reply to newSAS2017

When posting questions, look if there's a suitable community. My moving of your post to the IML community probably triggered @Rick_SAS's attention.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor
Posts: 8

Re: Creating data set from specific columns in other data set iml

Posted in reply to KurtBremser

Thanks - will do

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 232 views
  • 0 likes
  • 3 in conversation