BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

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=""];

 

2 REPLIES 2
Ksharp
Super User

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;

 

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 221 views
  • 0 likes
  • 3 in conversation