Hi Everyone,
I am a beginner to SAS and have been using the following code to count missing values for all variables in a dataset. However, this code is printing the output in a horizontal table. I need to get in a vertical table as I have too many variables but not sure how to make that possible. By vertical I mean getting the variables as rows instead of columns. Thank you for the help in advance.
proc iml;
use MBS4;
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 MBS4;
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=""];
quit;
/*Why not post it at IML forum? since it is about IML.
https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/bd-p/sas_iml
*/
data MBS4;
set sashelp.heart;
run;
proc iml;
use MBS4;
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 MBS4;
c = countn(x,"col");
cmiss = countmiss(x,"col");
/* combine results for num and char into a single table */
Names = t(cNames || nNames);
rNames = {" Missing", "Not Missing"};
cnt = (cmiss`//nmiss`) || (c` // n`);
print cnt[r=Names c=rNames label=""];
quit;
Use PROC FREQ for this:
proc freq data=have;
tables _all_ / missing;
run;
From this, play around with output datasets (OUTPUT statement or OUTPUT= option of TABLES).
/*Why not post it at IML forum? since it is about IML.
https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/bd-p/sas_iml
*/
data MBS4;
set sashelp.heart;
run;
proc iml;
use MBS4;
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 MBS4;
c = countn(x,"col");
cmiss = countmiss(x,"col");
/* combine results for num and char into a single table */
Names = t(cNames || nNames);
rNames = {" Missing", "Not Missing"};
cnt = (cmiss`//nmiss`) || (c` // n`);
print cnt[r=Names c=rNames label=""];
quit;
Thank you All!! All of these are working well. I just went with @Ksharp's as it gave me more compact table.
An alternate:
proc format;
value m
. = 'Missing'
other='Not missing'
;
value $m
'',' '='Missing'
other='Not missing'
;
run;
proc tabulate data=sashelp.heart;
class _all_ /missing;
classlev _all_/ style=[just=r];
format _numeric_ m. _character_ $m.;
table _all_,
n
;
run;
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.