BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JBerry
Quartz | Level 8

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

3 REPLIES 3
stat_sas
Ammonite | Level 13

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.

JBerry
Quartz | Level 8

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)

Reeza
Super User

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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