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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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