You're right, there seems to be no way to get TABULATE to produce an empty table, even when it would make perfect sense. Empty tables are always dropped. Consider :
data test;
page = 1;
cat = "A"; line=1; x=1; output;
cat = "B"; line=2; x=1; output;
run;
proc format;
value $cat
"A" = "A"
"B" = "B"
"C" = "C"
"D" = "D"
"E" = "E";
value line
1 = 1
2 = 2
3 = 3
4 = 4;
value page
1 = 1
2 = 2;
run;
proc tabulate data=test missing format=2.;
format cat $cat. line line. page page.;
class cat line page / preloadfmt;
var x;
table page, line, cat*x=""*mean="" / printmiss;
run;
/* Another approach that would make sense */
data myClassData;
do page = 1, 2;
do line = 1 to 4;
do cat = "A","B","C","D","E";
output;
end;
end;
end;
run;
proc tabulate data=test classdata=myClassData exclusive format=2.;
class cat line page;
var x;
table page, line, cat*x=""*mean="";
run;
With both approaches, the empty table on page 2 is dropped.
PG
PGStats: you're so close to what works though! Just need the x=0 line and tabulate will play.
data myClassData;
do page = 1, 2;
do line = 1 to 4;
do cat = "A","B","C","D","E";
x= 0;
output;
end;
end;
end;
run;
x = 0; would be ignored in the CLASSDATA dataset. The CLASSDATA dataset only indicates to the procedure what class combinations you want in your output. I did include page=2 in there, so I explicitly request a page 2 table. But tabulate decides to drop it anyway! Odd...
PG
Ah sorry, I misread what you were doing there.
Here's the\A solution for the original problem, should anyone ever come here looking for how to get it.
data real;
do numbers = 1,2,3,4;
do letters = 'A','B','C','D';
output;
end;
end;
run;
proc format;
value $L
'A'='A'
'B'='B'
other = 'X';
run;
data dummy;
do letters = 'A','B','C','D','E';
numbers = 0;
output;
end;
run;
data out;
set real dummy;
run;
option missing = 0;
proc tabulate data=dummy missing;
where letters = 'E';
class letters/preloadfmt;
var numbers;
tables (letters='')*(
numbers * sum='' *f=comma24.0 )
/printmiss;
format letters $l.;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.