How should I change my code? The first one works while the second one doesn't. Like the second code, I would like to get the reported numbers formatted with comma.
*It works;
proc report data= sashelp.heart missing;
column status sex, n;
define status/ group;
define sex/ across; run;
*It doesn' work.;
proc report data= sashelp.heart missing;
column status sex, n;
define status/ group;
define sex/ across format= comma9.2; run;
Hi:
You can't supply a numeric format for a character variable. You want to format the N statistics that is being placed UNDER the value of the SEX variable in the output table. Call Define is one approach. An even simpler approach is to use the format= or f= in a DEFINE statement for the N statistic, as shown below:
Cynthia
You want to put commas in the variable SEX? I am not understanding this.
This is what I get from the first code.
Sex Female Male Status n n Alive 1977 1241 Dead 896 1095
This is what I would like to get.
Sex Female Male Status n n Alive 1,977 1,241 Dead 896 1,095
So you want the comma in the value of N, not in the value of SEX as originally implied by your program.
I do not know if there is a way to format a statistic like N in the column statement. However, it is possible to format N in the CALL DEFINE statement, but you have to compute the statistic N for a specific variable, such as AGEATSTART (or any other variable you'd like to use)
proc report data= sashelp.heart missing;
column ("Status" status) sex, ageatstart;
define status/ group ' ';
define sex/ across;
define ageatstart/n ' ';
compute ageatstart;
call define(_col_,'format',"comma8.0");
endcompute;
run;
Hi @braam
The sex variable cannot have the format comma9.2 for its modalities.
You need to add as statement for "n" to apply this format:
proc report data= sashelp.heart missing;
column status sex, n;
define status/ group;
define sex/ across;
define n / format= comma9.2;
run;
Hi:
You can't supply a numeric format for a character variable. You want to format the N statistics that is being placed UNDER the value of the SEX variable in the output table. Call Define is one approach. An even simpler approach is to use the format= or f= in a DEFINE statement for the N statistic, as shown below:
Cynthia
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.