DATA Step, Macro, Functions and more

Missing values frequencies filtered by variables

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 81
Accepted Solution

Missing values frequencies filtered by variables

[ Edited ]

 

 

data have;
input Age $ Race $ Ethnicity $Gender $ DATE1: ddmmyy10. Class ;
FORMAT DATE1 MMDDYY10.;
datalines;
10 W C . 02/01/2017 1
. W C M 03/04/2015 2
. W C F 01/01/2016 2
;
run;

 

The final table should look like this but I want to be able to filter this output by date (year, qtr, month) and class:

 

                Missing        Not Missing           Total       year       Class

Age             2                      1                        3

Race           0                      3                        3

Ethnicity      0                      3                        3

Gender        1                      2                        3

 

I tried this code:

*create format for missing;
proc format ;
	value $ missfmt ' '="Missing" other="Not Missing";
	value nmissfmt .="Missing" other="Not Missing";
run;
/* Created "Year" variable using teh date field and used that in proc freq:*/
*Proc freq to count missing/non missing;
ods table onewayfreqs=temp;
proc freq data=class;
	table _all_ / missing;
	format _numeric_ nmissfmt. _character_ $missfmt.;
by year class; run; *Format output; data want; length variable $32. variable_value $50.; set temp; Variable=scan(table, 2); Variable_Value=strip(trim(vvaluex(variable))); keep variable variable_value frequency percent cum:; label variable='Variable' variable_value='Variable Value'; run;
But I dont know how can I format the output by variables e.g. (date (year, qtr, month) and class).

Thank you

 


Accepted Solutions
Solution
‎08-23-2017 12:43 PM
Super User
Posts: 23,262

Re: Missing values frequencies filtered by variables

I understand your problem and I know what you want, I just don't want to code it for you.

 

Feel free to wait for someone else, but the change is literally less than 65 characters. 

 

If you look at the output data set from PROC FREQ and read through the last DATA step I think you'll see clearly where you need to change the code. 

 

 

View solution in original post


All Replies
Super User
Posts: 23,262

Re: Missing values frequencies filtered by variables

That's the answer to the previous question, please show what you've done to answer this question.

Frequent Contributor
Posts: 81

Re: Missing values frequencies filtered by variables

Thank you,
I tried to sort the data by class and used 'by' statement. Edited proc freq to show what I did.
Best
Super User
Posts: 23,262

Re: Missing values frequencies filtered by variables


AZIQ1 wrote:
Thank you,
I tried to sort the data by class and used 'by' statement. Edited proc freq to show what I did.
Best

And did that work? What's the issue with the code now?

 

 

Frequent Contributor
Posts: 81

Re: Missing values frequencies filtered by variables

I think I am having trouble explaining it correctly. My apologies.
The code isn't working means its not giving me the output that I want.
I want the output to show frequencies of missing and non missing by Year and Class.
The output should look like this:


year class missing nonmissing total
Thank you

Solution
‎08-23-2017 12:43 PM
Super User
Posts: 23,262

Re: Missing values frequencies filtered by variables

I understand your problem and I know what you want, I just don't want to code it for you.

 

Feel free to wait for someone else, but the change is literally less than 65 characters. 

 

If you look at the output data set from PROC FREQ and read through the last DATA step I think you'll see clearly where you need to change the code. 

 

 

Frequent Contributor
Posts: 81

Re: Missing values frequencies filtered by variables

Thank you.
Super User
Posts: 23,262

Re: Missing values frequencies filtered by variables

Did you get it working? 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 157 views
  • 1 like
  • 2 in conversation