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

Hi.

I need to create a multiple array (81,81).

I've 3 columns in my data. 1st and 2nd column values ranges from 1 to 81 (these are codes for Provinces) and the 3rd column shows the distance between these provinces. The data structure is like:

A     B     C

1     2     200

1     3     500

.     .     .

1     81     300

2     1     100

2     3     250

.     .     .

81     80     1000;

I need to create an array/table/matrix which is 81 by 81 and shows the distance (3rd column value) between these provinces (1st and 2nd columns values).

Thanks in advance.    

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Try transpose:

data have;
  infile datalines;
  input a b c;
datalines;
1 2 200
1 3 30
1 5 23
2 1 27
2 4 8
2 5 90
;
run;

proc sort data=have;
  by a b c;
run;
proc transpose data=have out=want (drop=_name_) prefix=B;
  by a;
  var c;
  id b;
  idlabel b;
run;

The above will create Bx variables for each unique occurrence of a value in B.

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Try transpose:

data have;
  infile datalines;
  input a b c;
datalines;
1 2 200
1 3 30
1 5 23
2 1 27
2 4 8
2 5 90
;
run;

proc sort data=have;
  by a b c;
run;
proc transpose data=have out=want (drop=_name_) prefix=B;
  by a;
  var c;
  id b;
  idlabel b;
run;

The above will create Bx variables for each unique occurrence of a value in B.

data_null__
Jade | Level 19

Shouldn't the distance between a=1 and b=2 be the same as a=2 and b=1?

fayyazcivil
Calcite | Level 5

Hi. Thanks for your reply.

Yes it is, I just mentioned randomly Smiley Happy.

sas-innovate-2024.png

Available on demand!

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

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 579 views
  • 0 likes
  • 3 in conversation