Turn on suggestions

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

Showing results for

Options

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 05-24-2016 09:11 AM
(2062 views)

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

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

13 REPLIES 13

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

That is so good. Great learning experience! Thanks.

**SAS Innovate 2025** is scheduled for May 6-9 in Orlando, FL. Sign up to be **first to learn** about the agenda and registration!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.