BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Wub_SAS
Obsidian | Level 7

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; 
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
/*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; 

Ksharp_0-1686051735734.png

 

View solution in original post

4 REPLIES 4
Ksharp
Super User
/*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; 

Ksharp_0-1686051735734.png

 

Wub_SAS
Obsidian | Level 7

Thank you All!! All of these are working well. I just went with @Ksharp's as it gave me more compact table.

ballardw
Super User

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 4 replies
  • 1005 views
  • 3 likes
  • 4 in conversation