BookmarkSubscribeRSS Feed
AlexeyS
Pyrite | Level 9

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
Ksharp
Super User

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?

AlexeyS
Pyrite | Level 9

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.

Reeza
Super User

Is this related to your clustering question? Do you have SAS/STAT licensed?

AlexeyS
Pyrite | Level 9

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.

Reeza
Super User

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. 

AlexeyS
Pyrite | Level 9

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

Ksharp
Super User

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 .

Code: Program

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

AlexeyS
Pyrite | Level 9

thank you

Reeza
Super User

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.

AlexeyS
Pyrite | Level 9

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

Reeza
Super User

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.

SAS Innovate 2025: Save the Date

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

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 2291 views
  • 2 likes
  • 3 in conversation