Hello
I want to calculate number of missing values for each variable in data set (numeric/Char).
I saw this code.(SAS/IML language)
I want to ask-
How can I calculate it only for Make='Audi' ?(I found solution using (Where=(Make='Audi')) so i think it is fine)
How can I export result into a data set?
proc iml;
use sashelp.cars(Where=(Make='Audi'));
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 sashelp.cars;
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=""];
You should post it at IML forum, since it is relative to SAS/IML module.
Anyway, here is what you are looking for.
proc iml;
use sashelp.cars(Where=(Make='Audi'));
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 sashelp.cars;
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=""];*/
create want from cnt[r=rNames c=Names];
append from cnt[r=rNames];
close;
quit;
So it seems to me your real question is how to save the PROC IML results as actual SAS data sets. It would be desirable if you helped other users, and changed the title to reflect the real question you are asking.
IML has commands such as CREATE and APPEND to create actual SAS data sets from your results. Please see https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/imlug/imlug_langref_sect097.htm for many examples.
sasinnovate.png
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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ドル!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.