Help using Base SAS procedures

PROC FREQ

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

PROC FREQ

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. 


Accepted Solutions
Solution
‎09-08-2014 02:34 PM
Regular Contributor
Posts: 233

Re: PROC FREQ

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;

Capture.JPG

It would be more helpful if you can throw some data.

View solution in original post


All Replies
Trusted Advisor
Posts: 1,204

Re: PROC FREQ

ODS OUTPUT ONEWAYFREQS=want;
proc freq data=have;
table var1 var2;
run;

proc print data=want;
run;

Solution
‎09-08-2014 02:34 PM
Regular Contributor
Posts: 233

Re: PROC FREQ

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;

Capture.JPG

It would be more helpful if you can throw some data.

Super User
Posts: 17,784

Re: PROC FREQ

If you have both character and numeric variables consider this piece of code:

SAS - Missing Macro - For a dataset, variable level report the number of missing and non-missing obs...

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;

Valued Guide
Posts: 765

Re: PROC FREQ

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).

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 313 views
  • 1 like
  • 5 in conversation