BookmarkSubscribeRSS Feed
elwayfan446
Barite | Level 11

Hello,

 

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=""];
2 REPLIES 2
Rick_SAS
SAS Super FREQ

Instead of 

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

use

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 http://blogs.sas.com/content/iml/2011/04/18/writing-data-from-a-matrix-to-a-sas-data-set.html"Writing data from a matrix to a SAS data set."

elwayfan446
Barite | Level 11

Thank you Rick.  I will give this a try!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 1767 views
  • 0 likes
  • 2 in conversation