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

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- array

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
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-15-2015 03:18 AM

Hello, i have two variables, and i need to present them as array two dimension. how to do that?

for example, i have two varibles: salary and years_of_study

salary years_of_study

10000 10

15000 12

12000 13

20000 14

and i want to get the next array {4,2} .

How to do that?

thank you

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

Posted in reply to AlexeyS

06-15-2015 08:30 AM

The simplest way is using IML .

And you want do under data step? and what kind of array would like to use ? temporary array or variable array?

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

Posted in reply to Ksharp

06-15-2015 02:20 PM

Hello , thank you for your answer.

I develop Kernel K-means by myself and unfortunately i don't have SAS/IML, otherwise i didn't had a problem.

i tried to do it with arrays and i saw i have a problem, i simply can't do it.

i saw two problems :

1. i get two column vector and i want to define them as matrix , and i couldn't do it.(d-dimension)

for example :

d1 d2

x1 1 2

x2 0.1 3

x3 -1 1.1

i want to define matrix as 3*2 with array

2. assume i did it' i created kernel matrix, and i need in first step to choose two random observation for clustering, and because it as if matrix, i can't random choose row, because in SAS, i have only one row.

what do you think about the problem? in my opinion we have to buy IML, i can't to solve matrix problems with basic tools.

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

Posted in reply to AlexeyS

06-15-2015 02:51 PM

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

Posted in reply to Reeza

06-15-2015 03:05 PM

yes, i have sas stat, but not sas/iml.

I develop Kernel K-means by myself and unfortunately i don't have SAS/IML, otherwise i didn't had a problem.

i tried to do it with arrays and i saw i have a problem, i simply can't do it.

i saw two problems :

1. i get two column vector and i want to define them as matrix , and i couldn't do it.(d-dimension)

for example :

d1 d2

x1 1 2

x2 0.1 3

x3 -1 1.1

i want to define matrix as 3*2 with array

2. assume i did it' i created kernel matrix, and i need in first step to choose two random observation for clustering, and because it as if matrix, i can't random choose row, because in SAS, i have only one row.

what do you think about the problem? in my opinion we have to buy IML, i can't to solve matrix problems with basic tools.

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

Posted in reply to AlexeyS

06-15-2015 03:20 PM

I don't know why you're trying to do it from scratch but you can probably still do it in a data step or via macro's with a bit of wrangling.

If you can illustrate your calculations on a 3x2 matrix perhaps someone can help with that solution instead.

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

Posted in reply to Reeza

06-15-2015 03:31 PM

i tried to do it in data step, but without success.

i wrote two problems i have in data step.

for example, if you import excel with two dimension, how can i create array as is, i.e define array 3*2 :

d1 d2

x1 1 2

x2 0.1 3

x3 -1 1.1

after i create array, i have to get :

y1 y2 y3 y4 y5 y6

1 2 0.1 3 -1 1.1

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

Posted in reply to AlexeyS

06-16-2015 08:42 AM

SAS University Edition has IML , and it is totally free, you can download it at sas.com .

And You seem to want create a temporary array .

data have;

input salary years_of_study;

cards;

10000 10

15000 12

12000 13

20000 14

;

run;

%let dsid=%sysfunc(open(have));

%let row=%sysfunc(attrn(&dsid,nlobs));

%let col=%sysfunc(attrn(&dsid,nvars));

%let dsid=%sysfunc(close(&dsid));

data _null_;

set have end=last;

array x{&row,&col} _temporary_;

array z{*} _numeric_;

do i =1 to dim(z);

x{_n_,i}=z{i};

end;

drop i;

if last then put x{1,1}= x{1,2}= /

x{2,1}= x{2,2}=;

run;

Xia Keshan

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

Posted in reply to Ksharp

06-25-2015 07:54 AM

thank you

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

Posted in reply to AlexeyS

06-15-2015 02:35 PM

Why do you need a 2 dim array? If you're not in IML your data is not structured in a format for a 2 dim array.

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

Posted in reply to Reeza

06-15-2015 03:08 PM

i need it because i have to create kernel matrix and then work on matrix

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

Posted in reply to AlexeyS

06-15-2015 03:48 PM

Basically, if you're doing it from base without IML you have to do all the matrix calculations yourself. It's possible but you have to go straight back to the basics and understand all the matrix algebra etc.

You can always use R anyways. Google for ProcR that allow SAS to call R without IML.