- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You want to put commas in the variable SEX? I am not understanding this.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Tags:
- proc report
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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