## How to create a sparse matrix?

Hello,

Currently we have some problemes with using SAS.

We have used the following code

PROC IMPORT OUT= WORK.FRAUD

DATAFILE= "C:\..."

DBMS=CSV REPLACE;

GETNAMES=YES;

DATAROW=2;

RUN;

This datafile contains 3958352 records.

Now we want to make a sparse matrix from this datafile.

Do you guys know how we can do this?

We found some example code on the internet:

x = {3 1.1 0 0 ,

1.1 4 0 3.2,

0 1 10 0 ,

0 3.2 0 3 };

a = sparse(x, "sym");

print a[colname={"Value" "Row" "Col"}];

But we don't know how to say that x containts the dataset work.fraud.

We couldn't find anything on the sas community.

Kind regards

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: How to create a sparse matrix?

Looks about right. I think the conclusion is that general-purpose tools are fine for analyzing networks that have thousands of nodes. This includes all the famous examples that you see of Hollywood stars, members of Fortune 500 boards, authors of papers in statistics journals, and characters in movies like Star Wars or Lord of the Rings. But for  huge networks with hundred of thousands or millions of nodes, special purpose tools such as SAS Social Network Analysis and SAS Fraud Network Analysis | SAS are more efficient.

9 REPLIES 9

## Re: How to create a sparse matrix?

What do you want to do with the matrix after it is in a SAS/IML? Is it square? If not, how many columns does it have? data_null__

## Re: How to create a sparse matrix?

This might help.

data xdata;
input x1-x4;
cards;
3 1.1 0 0
1.1 4 0 3.2
0 1 10 0
0 3.2 0 3
;;;;
run;
proc iml;

use xdata;
read all var _num_ into x;
close xdata;
print x;

a = sparse(x,
"sym");
print a[colname={"Value" "Row" "Col"}];
quit;

## Re: How to create a sparse matrix?

We want to do some calculations like pagerank, cliques, betweeness but before we can do this, we need a sparse matrix dataset.

Here you can see a few lines of the matrix (3 columns)

"Row","Col","Value"

830,3,1

852,3,1

52591,3,1

114337,3,1

148326,3,1

196849,3,1

...

So how can we make a sparse matrix of this , so we can do our calculations on sparse matrix dataset?

Kind regards

Bart

## Re: How to create a sparse matrix?

Based on your response, see the discussion at https://communities.sas.com/message/204360#204360

You might also want to read the papers by  Hector Rodriguez-Deniz

in the proceedings of SAS Global forum 2012 and 2013.

## Re: How to create a sparse matrix?

Hello we can't use SNA, since we don't have a license for it.

We should calculate pagerank / betweenness / cliques / pagerank for our (fraud) matrix, but we can't do this since we cannot make a sparse matrix.

Any suggestions?

## Re: How to create a sparse matrix?

I suggest you think carefully about what you are attempting.  Whether a sparse representation of a 4M x 4M matrix can even fit in memory depends on the percentage of nonzero elements and the RAM of your system.  The matrix has 1.6 x 10^13 elements.  If 1% of those are nonzero, you are still looking at 1.6 TRILLION elements. Stored as a sparse matrix, this requires 4.8 trillion doubles, which is 38.4 trillion bytes, which is about  38.4 TERABYTES of data.

That amount of RAM is needed just to store the data. The algorithms that you mention have nontrivial computational complexity and require additional memory. This is why many people use specialized tools and algorithms for network analysis of very large networks.

## Re: How to create a sparse matrix?

Since our matrix is just 400 000 x 400 000 but I guess that is also too big?

Are these calculations right:

400 000 x 400 000 = 1,6 x 10^11 and we have 0,4% nonzero elements so we are looking for 640000000 items.

Stored as a sparse matrix, this requires 1920000000 doubles which is 1,79 TB of data.

Am I right, so we could only juse specialized tools and algorithms for network analysis?

Bart

## Re: How to create a sparse matrix?

Looks about right. I think the conclusion is that general-purpose tools are fine for analyzing networks that have thousands of nodes. This includes all the famous examples that you see of Hollywood stars, members of Fortune 500 boards, authors of papers in statistics journals, and characters in movies like Star Wars or Lord of the Rings. But for  huge networks with hundred of thousands or millions of nodes, special purpose tools such as SAS Social Network Analysis and SAS Fraud Network Analysis | SAS are more efficient.

## Re: How to create a sparse matrix?

Thanks!

We would like to calculate 4 metrics for a small network (only 15x15 nodes).

We would like to calculate betweenness centrality , pagerank centrality, cliques, assortativity.

Is it possible to calculate them without using IML?

Currently it is not possible we guess.

Regards

From The DO Loop
{"ft_lang_label":"__label__en","ft_lang_prob":0.9143627,"math_prob":0.91598684,"size":4573,"snap":"2023-40-2023-50","text_gpt3_token_len":1114,"char_repetition_ratio":0.09936529,"word_repetition_ratio":0.23017903,"special_character_ratio":0.25584954,"punctuation_ratio":0.13865547,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9516111,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-02T11:34:20Z\",\"WARC-Record-ID\":\"<urn:uuid:8580f2f4-6b01-4747-bf02-3437ae001ffc>\",\"Content-Length\":\"336178\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:81f8e060-3c0c-4194-8213-20c72f28f964>\",\"WARC-Concurrent-To\":\"<urn:uuid:add724d4-f4ed-467c-8fbc-df30722a2d8a>\",\"WARC-IP-Address\":\"18.67.65.90\",\"WARC-Target-URI\":\"https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-a-sparse-matrix/td-p/173717\",\"WARC-Payload-Digest\":\"sha1:LVYXBTXE3KXXCPG35CWRR3ZSYOMOBZSC\",\"WARC-Block-Digest\":\"sha1:OMWBL6TLYFPZL4NXA2K72FQJZ7GV3L3E\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100399.81_warc_CC-MAIN-20231202105028-20231202135028-00212.warc.gz\"}"}