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=""];
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."
Thank you Rick. I will give this a try!
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!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.