BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hkbenlyl
Calcite | Level 5

Dear all,

I want to create a two dimensional array from my dataset. 

Here is my sample dataset

h.JPG

 

 

 

 

 

 

 

 

 

 

 

And I would like to create a 2 dimensional array like this

es.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Hi and welcome to the SAS Communities 🙂

 

You can do like this

data have;
input row col num;
datalines;
1 1 1
1 2 2
1 3 3
2 1 4
2 2 5
2 3 6
3 1 7
3 2 8
3 3 9
;

data want;
   set have end=lr;
   array MyArray {3, 3} _temporary_;
   MyArray[row, col]=num;

   /* Verify that the values are correctly assigned */
   if lr;
   do i=1 to 3;
      do j=1 to 3;
         put (MyArray[i, j])(=);
      end;
   end;
run;  

 

This prints 

Capture.PNG

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Hi and welcome to the SAS Communities 🙂

 

You can do like this

data have;
input row col num;
datalines;
1 1 1
1 2 2
1 3 3
2 1 4
2 2 5
2 3 6
3 1 7
3 2 8
3 3 9
;

data want;
   set have end=lr;
   array MyArray {3, 3} _temporary_;
   MyArray[row, col]=num;

   /* Verify that the values are correctly assigned */
   if lr;
   do i=1 to 3;
      do j=1 to 3;
         put (MyArray[i, j])(=);
      end;
   end;
run;  

 

This prints 

Capture.PNG

Ksharp
Super User

Do you have IML ?

 

data have;
input row col num;
datalines;
1 1 1
1 2 2
1 3 3
2 1 4
2 2 5
2 3 6
3 1 7
3 2 8
3 3 9
;
proc iml;
use have;
read all var {row col num};
close;
x=num||row||col;
have=full(x);
print have;

quit;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 2 replies
  • 1333 views
  • 1 like
  • 3 in conversation