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

05-24-2016 09:11 AM

I need to read the values of the dependent variable y from the sas data I created into an n * K matrix, where n is the number of obs in each group and k is the number of levels of my cateogrial variable. i need first to write k statements to read the obs from the dataset into k column vectors of dimension nX1, then needd to write a statment that horizontally concatenates these k columns vectors to form the n * k matrix

w

Accepted Solutions

Solution

05-25-2016
02:57 PM

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

Posted in reply to wenling

05-25-2016 02:38 PM

All Replies

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

Posted in reply to wenling

05-24-2016 10:08 AM

You may need to supply some more details on how the SAS data set is structured to get better help. However, my feeling is that you would be better to read the variable y into one vector, and then manipulate this is IML. For example look at the SHAPE function which can be used to turn a vector into a matrix.

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

Posted in reply to IanWakeling

05-24-2016 10:17 AM

a SAS data set that contains one continuous variable (*y*) and one categorical variable (*x*) with at least three levels. These are to be used as my continuous dependent variable and categorical independent variable in my single factor ANOVA model

then i will need to do sas iml

i have three groups, each has 11 obs

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

Posted in reply to wenling

05-24-2016 10:31 AM

My suggestion to use SHAPE works as long as all the groups have the same size **and** the SAS data set is sorted by group. Then you could use code like this:

```
use mydata;
read all var {y} into y;
z = t( shape(y, 3, 11) );
print z;
```

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

Posted in reply to IanWakeling

05-24-2016 10:37 AM

Thanks

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

Posted in reply to IanWakeling

05-24-2016 10:42 AM

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

Posted in reply to Rick_SAS

05-24-2016 10:45 AM

thanks

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

Posted in reply to Rick_SAS

05-25-2016 11:20 AM

Then I realize I might need alternative code, that is, do not use 11, 3, but use a more general code, so that it can be fit for other similiar kind of dataset as well.

My question is, if others have simiar dataset, but instead of 11 obs, they have 20 obs, five categories, another dataset have 50 obs, four categories, can I have a more general code so that the code can be used for other datasets as well, "one size fits all"?

Thanks

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

Posted in reply to wenling

05-25-2016 11:53 AM

You need to know either how many categories or how many obsevations. You also need to make sure that each group has the same number of elements.

The best situation is if you have a categorical variable that tells you the group that each observations is associated with. Then you could do something like this

read all var {Group y};

numGroups = ncol(unique(Group));

z = shapecol(y, **0**, numGroups);

If you don't have a GROUP variable, you'll have to input the numGroups value manually.

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

Posted in reply to Rick_SAS

05-25-2016 12:04 PM

I do have a variable "Tem", it is a charactor not a numeric. It has three catogories

**proc** **iml**;

reset print;

use have;

read all var {tem y};

numGroups = ncol(unique(tem));

z = shapecol(y, **0**, numGroups);

ERROR: Y is not in the scope of variables for the data set.

does it mean that I have to convert the charactor to numeric variable?

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

Posted in reply to wenling

05-25-2016 02:05 PM

No, the error is saying that you do not a variable named 'Y'.

Here is some data that shows you how it works:

```
data have;
do tem = 'A', 'B', 'C';
do i = 1 to 5;
y = rand("uniform");
output;
end;
end;
proc iml;
use have;
read all var {tem y};
numGroups = ncol(unique(tem));
z = shapecol(y, 0, numGroups);
print z;
```

By the way, you mistakenly choose your own post as the solution. :-)

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

Posted in reply to Rick_SAS

05-25-2016 02:32 PM

Thank you very much. This does show me how it works. . But my question remained unsolved, if I need a general code, rather than to type the number 3 and 11

Solution

05-25-2016
02:57 PM

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

Posted in reply to wenling

05-25-2016 02:38 PM

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

Posted in reply to Rick_SAS

05-25-2016 02:57 PM

That is so good. Great learning experience! Thanks.