BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ksharp
Super User
/*
You need process them bofore PROC IML.
*/
proc import datafile='c:\temp\book6.xlsx' out=Sheet1 dbms=xlsx replace;
sheet='Sheet1';
run;
proc import datafile='c:\temp\book6.xlsx' out=Sheet2 dbms=xlsx replace;
sheet='Sheet2';
run;

proc iml ;
use sheet1(where=(id is not missing)) ;
read all var _num_ into layer1 ;
close;
use sheet2(where=(id is not missing)) ;
read all var _num_ into layer2 ;
close;

 
/*There are only 9 columns(exclude ID),so should be 8:9*/
A = layer1[1:2,8:9] ;
B = layer2[1:2,8:9] ;
c = A # B ;
quit;
Max123
Obsidian | Level 7
why aren't matrices A, B, C created in the work lib?
Rick_SAS
SAS Super FREQ

Because they are not data sets. They are matrices, which are created in RAM. They disappear after you QUIT the procedure.

If you need to write the final result to a data set, you can do that by using the CREATE/APPEND statements:
https://blogs.sas.com/content/iml/2011/04/18/writing-data-from-a-matrix-to-a-sas-data-set.html 

Ksharp
Super User
/*
Follow the Rick's blog,
You need more code to save these matrix .
*/

proc iml ;
use sheet1(where=(id is not missing)) ;
read all var _num_ into layer1 ;
close;
use sheet2(where=(id is not missing)) ;
read all var _num_ into layer2 ;
close;

A = layer1[1:2,8:9] ;
B = layer2[1:2,8:9] ;
c = A # B ;

create want var{A B C};
append;
close;
quit;
Tom
Super User Tom
Super User

If the nodes are identified by a series of integers (and if not you could always just sort and number them) 

And the number of nodes is reasonable (and if not you are going to have a hard time doing calculations).

 

Then just make a 2-D array.  You can then write the 2-D array out as a dataset.

 

Example:

data have;
  input from to ;
cards;
1  2
1  3
4  5
5  2
6  7
8  7
;

data matrix ;
  array x[8,8] _temporary_ (64*0);
  do until (eof);
    set have end=eof;
    x[from,to]=1;
    x[to,from]=1;
  end;
  do node=1 to 8;
    array nodes [8] node1-node8 ;
    do col=1 to 8;
      nodes[col]=x[node,col];
    end;
    output;
  end;
  keep node: ;
run;

Result

Obs    node    node1    node2    node3    node4    node5    node6    node7    node8

 1       1       0        1        1        0        0        0        0        0
 2       2       1        0        0        0        1        0        0        0
 3       3       1        0        0        0        0        0        0        0
 4       4       0        0        0        0        1        0        0        0
 5       5       0        1        0        1        0        0        0        0
 6       6       0        0        0        0        0        0        1        0
 7       7       0        0        0        0        0        1        0        1
 8       8       0        0        0        0        0        0        1        0

If you want the main diagonal to be 1's then add this statement after the ARRAY statement in the DO NODE loop.

    nodes[node,node]=1;
PGStats
Opal | Level 21

This page references 7 different measures of node centrality.

 

Which centrality measure do you want to calculate? And do you want to do the calculation with SAS or simply provide a well formatted file to other software?

PG
Max123
Obsidian | Level 7
Ultimately, I want the centrality (eigenvector, degree, betweenness, closeness) scores for each node, in SAS... I don't actually care for the intermediate steps. It was my assumption that I needed the adj. matrix before calculating the scores
Tom
Super User Tom
Super User

@Max123 wrote:
Ultimately, I want the centrality (eigenvector, degree, betweenness, closeness) scores for each node, in SAS... I don't actually care for the intermediate steps. It was my assumption that I needed the adj. matrix before calculating the scores

And how to you propose to calculate those scores?  

Do you know the algorithm needed?

Max123
Obsidian | Level 7
found this example online:
proc netflow in=network out=degree_centrality action=stats;
stats degree / type=degree;

PGStats
Opal | Level 21

These network (graph) statistics are now available from PROC OPTGRAPH, for which you need the SAS Network Algorithms license.

 

From the procedure documentation, you only need a links (i.e. from-to pairs) dataset to get it going.

 

The centrality statistics are requested with the CENTRALITY statement.

PG
Max123
Obsidian | Level 7
unfortunately, I don't have that license. and PROC NETFLOW is not working...

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 25 replies
  • 3909 views
  • 15 likes
  • 5 in conversation