Help using Base SAS procedures

Proc Freq Output not Consistent

Accepted Solution Solved
Reply
Contributor
Posts: 64
Accepted Solution

Proc Freq Output not Consistent

When I run this statement on a dataset, I usually get 5 columns. TableVar, TableVarLabel, NLevels, NMissLevels, NNonMissLevels

ods output nlevels=nlevelsds;

proc freq data=LIB.DATASET nlevels;

tables _all_/noprint;

run;

But when I change the dataset to a different dataset, I only get 3 columns!   TableVar, TableVarLabel, NLevels

Why?  Would this happen if my dataset had no missing values?

Is there a way to force these columns to appear?

The unpredictable output is really giving me problems with programming and automation.


Accepted Solutions
Solution
‎07-18-2014 03:06 PM
Super User
Posts: 19,769

Re: Proc Freq Output not Consistent

Create an empty table with all the columns expected and insert the output into it.  You'll also have to verify the variable type, character or numeric. Or use a different method entirely to generate your output.

But yes, the structure doesn't appear to be static and this is common pitfall of ODS tables. For example if you do a one way table versus a two way table in proc freq the output table names are different.

View solution in original post


All Replies
Trusted Advisor
Posts: 1,228

Re: Proc Freq Output not Consistent

This is happening because your second data set contains variables that don't have missing values. If at least one of the variables in your second dataset has missing values then you will get 5 columns in nlevelsds.

Contributor
Posts: 64

Re: Proc Freq Output not Consistent

Is there no way to force a consistent output? I would like to create macros, but if one of the

This blows my mind that the output structure is dependent upon the values of the data.... because when I automate a process, it will fail if the column doesnt exist (even though it SHOULD exist, just with a 0 for missing values)

Solution
‎07-18-2014 03:06 PM
Super User
Posts: 19,769

Re: Proc Freq Output not Consistent

Create an empty table with all the columns expected and insert the output into it.  You'll also have to verify the variable type, character or numeric. Or use a different method entirely to generate your output.

But yes, the structure doesn't appear to be static and this is common pitfall of ODS tables. For example if you do a one way table versus a two way table in proc freq the output table names are different.

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 241 views
  • 3 likes
  • 3 in conversation