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.
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 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.
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)
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.