Turn on suggestions

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

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- array

Options

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

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

Posted 06-15-2015 03:18 AM
(1745 views)

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

11 REPLIES 11

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

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

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

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

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

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

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

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

thank you

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

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

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

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

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.

**Available on demand!**

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.