Is there a way for me to output all of my tables generated from my PROC FREQ procedure into one dataset? I'm counting the number of null values in my dataset and would like to know if I can. Thanks in advance.
I'm not sure if this what you are looking for but want to give a shot.
data have;
input id;
datalines;
1
2
3
4
1
2
3
4
5
.
.
.
.
;
run;
proc freq data=have;
tables id /out=want;
run;
It would be more helpful if you can throw some data.
ODS OUTPUT ONEWAYFREQS=want;
proc freq data=have;
table var1 var2;
run;
proc print data=want;
run;
I'm not sure if this what you are looking for but want to give a shot.
data have;
input id;
datalines;
1
2
3
4
1
2
3
4
5
.
.
.
.
;
run;
proc freq data=have;
tables id /out=want;
run;
It would be more helpful if you can throw some data.
If you have both character and numeric variables consider this piece of code:
if all variables are numeric you can use proc means and the NMISS variable:
proc means data=help stackods n Nmiss;
output out=want ;
run;
hi ... here's an idea based on a recent posting by Ksharp on how to use PROC SQL to find variables with all missing data (should work for any data set since SQL does all the work of finding the variable names and doing the counting for you) ...
* some data with missing values;
data class;
set sashelp.class;
if ranuni(0) le 0.7 then call missing(age,name);
else if ranuni(0) le 0.4 then call missing(height);
call missing (weight);
run;
* take a look at the amount of missing ;
proc print data=class;
run;
* as suggested by Ksharp ... use NMISS to count missing values;
proc sql noprint;
select cat('nmiss(',strip(name),') as ',name) into :list separated by ','
from dictionary.columns
where libname='WORK' and memname='CLASS';
create table temp as select &list from class;
select count(*) into :nobs from class;
quit;
* make a report;
data report;
set temp;
array x{*} _numeric_;
do i=1 to dim(x);
var = vname(x(i));
miss = x(i);
pctmiss = round(100*miss / &nobs, 0.1);
output;
end;
keep var miss pctmiss;
run;
* look at the results;
proc print data=report
run;
ps You can also look at "An Easy Route to a Missing Data Report with ODS+PROC FREQ+A Data Step" ( http://www.lexjansen.com/nesug/nesug11/ds/ds12.pdf )
though if I were writing that now, I'd replace the use of ODS and PROC FREQ with SQL as suggested by Ksharp (a LOT less programming in the subsequent data step).
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.