BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RAVI2000
Lapis Lazuli | Level 10

I was trying to get decimal places for mean and median. I am only able to get decimal where there are zeros. How can I get decimals for other numbers?

S_RAVI_0-1622758779466.png

Proc format;
value misszero
0 = '0.0'
other = [2.1];
run;

proc report data = fin nowindows missing headline headskip center split = "|" ps = 47 ls = 133 spanrows
		style(report) = [cellwidth = 100% asis = on cellspacing = 0 cellpadding = 1.0pt borderwidth = 0.6  just = center protectspecialchars=off borderbottomcolor = black ] 
		style(header) = [asis = on just = center protectspecialchars=off font_weight = bold background = white fontsize=12pt ]
		style(column) = [asis = on just = center protectspecialchars=off vjust = bottom fontsize=12pt ];
		
		columns ("Assessment Time" segment_code) ("Dose Level" armcode,(N mean median));
		
		define segment_code/"" group descending format = segmentcode.
				style(column) = [just = left cellwidth = 15% font_weight = bold] style(header) = [just=left] flow id;
		
		define armcode/"" across format = armcode.
				style(column) = [just = center cellwidth = 0.12in] ;
		
		define N/analysis sum format = 2.0
				style(column) = [just = center cellwidth = 0.4in]; 
		
		define mean/analysis sum format = misszero.
				style(column) = [just = center cellwidth = 0.4in] ;
		
		define median/analysis sum format = misszero.
				style(column) = [just = center cellwidth = 0.4in] ;
run;

Also same output report, I want to reference the &n1, &n2 in the proc report code. I have created the macro variable but not able to use them in my proc report code. Not sure how I can use them.

Capture.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Proc format;
value misszero
0 = '0.00'
other = [8.2];
run;

What would you want to do with missing values? If you've taken care of that in a previous step it's fine to ignore it though.

View solution in original post

8 REPLIES 8
Reeza
Super User

You need to go back to the step where you converted them to character values and do it there. 

 

If you specify the format as 8.2 it will display with 2 decimal places. Obviously you cannot apply a numeric format to a character variable though. 

 

mean_char = put(mean, 8.2);

@RAVI2000 wrote:

I was trying to get decimal places for mean and median. I am only able to get decimal where there are zeros. How can I get decimals for other numbers?

S_RAVI_0-1622758779466.png

Proc format;
value misszero
0 = '0.0'
other = [2.1];
run;

proc report data = fin nowindows missing headline headskip center split = "|" ps = 47 ls = 133 spanrows
		style(report) = [cellwidth = 100% asis = on cellspacing = 0 cellpadding = 1.0pt borderwidth = 0.6  just = center protectspecialchars=off borderbottomcolor = black ] 
		style(header) = [asis = on just = center protectspecialchars=off font_weight = bold background = white fontsize=12pt ]
		style(column) = [asis = on just = center protectspecialchars=off vjust = bottom fontsize=12pt ];
		
		columns ("Assessment Time" segment_code) ("Dose Level" armcode,(N mean median));
		
		define segment_code/"" group descending format = segmentcode.
				style(column) = [just = left cellwidth = 15% font_weight = bold] style(header) = [just=left] flow id;
		
		define armcode/"" across format = armcode.
				style(column) = [just = center cellwidth = 0.12in] ;
		
		define N/analysis sum format = 2.0
				style(column) = [just = center cellwidth = 0.4in]; 
		
		define mean/analysis sum format = misszero.
				style(column) = [just = center cellwidth = 0.4in] ;
		
		define median/analysis sum format = misszero.
				style(column) = [just = center cellwidth = 0.4in] ;
run;

Also same output report, I want to reference the &n1, &n2 in the proc report code. I have created the macro variable but not able to use them in my proc report code. Not sure how I can use them.

Capture.PNG


 

Reeza
Super User
Proc format;
value misszero
0 = '0.00'
other = [8.2];
run;

What would you want to do with missing values? If you've taken care of that in a previous step it's fine to ignore it though.

RAVI2000
Lapis Lazuli | Level 10
I have assigned (updated) them as '-' in my proc format.
RAVI2000
Lapis Lazuli | Level 10
Any help with referencing the macro variable in the proc report to obtain N= ?
Reeza
Super User
Create macro variables and add that data to your ARMCODE variable.

Because you're using ACROSS option within PROC REPORT you cannot use use a label option. You might be able to do it via COMPUTE but it becomes harder to control your output and there's some reliance on order which can cause unexpected issues if you add another column or order changes. This needs to happen before the PROC REPORT step.

RAVI2000
Lapis Lazuli | Level 10

As said I have created the macro variables &n1, &n2, &n3. 

Can you explain how can I add them to my armcode variable?

*Counting and referencing Distinct subjects for arms;

proc sql;
	select max(0, count(distinct usubjid)) into :n1 trimmed
		from test
			where armcode = 1;
			
	select max(0, count(distinct usubjid)) into :n2 trimmed
		from test
			where armcode = 2;
			
	select max(0, count(distinct usubjid)) into :n3 trimmed
		from test
			where armcode = 3;
quit;

%put &n1 &n2 &n3;

They resolve to 3, 0, 0.

Now before the proc report how do I add them to the armcode variable?

ballardw
Super User

2.1 is too small. The Decimal counts as one of the 2 characters and if you have negative values that would want a character as well. It might help to show the range of values you are actually concerned with. As a minimum [3.1] will display values with 1 decimal, up to 9.9.  If you have mean or median values greater than 10 you need still more width for the format such as 4.1. The number before the period is the total number of characters the format will display.

Reeza
Super User
You'll find these references helpful though older. For what you're doing, not much has changed.

Paper
https://support.sas.com/resources/papers/proceedings/pdfs/sgf2008/173-2008.pdf

Code that goes along with papers
https://support.sas.com/rnd/papers/sgf2008/complex_reports.zip

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1144 views
  • 5 likes
  • 3 in conversation