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;

AI Navigator GIF.gif


Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.

Check it out on Microsoft Marketplace →

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
  • 1841 views
  • 1 like
  • 3 in conversation