BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
braam
Quartz | Level 8

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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:

format_define.png

 

Cynthia

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

You want to put commas in the variable SEX? I am not understanding this.

--
Paige Miller
braam
Quartz | Level 8

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
PaigeMiller
Diamond | Level 26

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
ed_sas_member
Meteorite | Level 14

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;
Cynthia_sas
SAS Super FREQ

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:

format_define.png

 

Cynthia

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 3748 views
  • 4 likes
  • 4 in conversation