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;
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;
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;
@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.
@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...
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.