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

Dear SAS experts, 

I want to just count missing frequency for all character variables by a categorical var (Year) in a dataset.  and have a output dataset. I only care about the missing count, so leave the not missing out. and I only want the character variables, so don't try to conquer all var in one shot and expect perfect results. (I've searched and tried, hasn't found one), but you do have a perfect solution that can do it all (by category and with results output), I think everyone would love to have it :). Keep it separate and keep it simple. Thanks.

The following is a simple code to do the numeric variable FYI. I want similar results for character variables: 

 

proc means data=sensit_dist nway noprint;
class infyob_yot;
output out=misschk n= nmiss= /autoname;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Something like this may get you started. Untested as we don't have your data.

The Value in the data step takes 1/0 values when the variable is missing for the named variable. This creates one record for each variable. The Proc summary/means sums the variable to get a total count of missing.

data temp;
   set sensit_dist;
   array c _character_;
length name $ 32; do i=1 to dim (c); name = vname(c[i]); value = (missing( c[i]));
output; end; keep infyob_yot name value ; run; proc summary data=temp nway; class infyob_yot name; var value; output out=work.charmissing Sum= ; run;

View solution in original post

3 REPLIES 3
ballardw
Super User

Something like this may get you started. Untested as we don't have your data.

The Value in the data step takes 1/0 values when the variable is missing for the named variable. This creates one record for each variable. The Proc summary/means sums the variable to get a total count of missing.

data temp;
   set sensit_dist;
   array c _character_;
length name $ 32; do i=1 to dim (c); name = vname(c[i]); value = (missing( c[i]));
output; end; keep infyob_yot name value ; run; proc summary data=temp nway; class infyob_yot name; var value; output out=work.charmissing Sum= ; run;
Xiaoyi
Obsidian | Level 7

@ballardw  Thanks for the code this look promising, but it only did for one variable. I had 37 character variables. I tried to tweak it a little bit to make it work, but I run it, and every time, it only counted one variables. It didn't give me a dataset with 37 variables in it. You can use any datasets you have to test it. 

ballardw
Super User

@Xiaoyi wrote:

@ballardw  Thanks for the code this look promising, but it only did for one variable. I had 37 character variables. I tried to tweak it a little bit to make it work, but I run it, and every time, it only counted one variables. It didn't give me a dataset with 37 variables in it. You can use any datasets you have to test it. 


Check the post with the code for the added OUTPUT statement.

The problem with not having a data set is code cannot be tested...

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!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 692 views
  • 1 like
  • 2 in conversation