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 open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.