Statistical programming, matrix languages, and more

PROC IML Questions

Frequent Contributor
Posts: 133

PROC IML Questions



I have recently been researching ways to come up with some basic statistics for the variable data in my datasets.  I found code that works well for me in THIS article by Rick Wicklin using proc iml.  I had some questions about his code but he is referring questions to this forum.  I want to take the following code that he used as an example in the blog and modify it to only pull back the variables I need.  Currently, it pulls back the statistics for all variables in the dataset.  I also am confused on how I would then export this to a dataset.  Could someone point me in the right direction on both of these questions?


proc iml;
use work.datagapanalysis;
read all var _NUM_ into x[colname=nNames]; 
n = countn(x,"col");
nmiss = countmiss(x,"col");
read all var _CHAR_ into x[colname=cNames]; 
close work.datagapanalysis;
c = countn(x,"col");
cmiss = countmiss(x,"col");
/* combine results for num and char into a single table */
Names = cNames || nNames;
rNames = {"    Missing", "Not Missing"};
cnt = (cmiss // c) || (nmiss // n);
print cnt[r=rNames c=Names label=""];
Posts: 3,225

Re: PROC IML Questions

Instead of 

read all var _NUM_ into x[colname=nNames];


nNames = {"var1" "var2" "var3"};
read all var nNames into x;

 Similarly, use

cNames = {"othervar1" "othervar2"};
read all var cNames into x;

 After you have formed the 'cnt' matrix, use the techniques in the article"Writing data from a matrix to a SAS data set."

Frequent Contributor
Posts: 133

Re: PROC IML Questions

Thank you Rick.  I will give this a try!

Post a Question
Discussion Stats
  • 2 replies
  • 2 in conversation