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

Hello SAS Community, 

Please anyone tell me why I'm getting an extra line of text when using compute before/after for 2 variables. Below is an example code.

Thank you!

data have;
input visit $ paramcd $ aval;
if find(paramcd, 'EQOL') gt 0 then gr=2;
else gr=1; 
cards;
Screen EQOL0101 2
Screen EQOL0102 4
Screen EQOL0103 3
Screen EQOL0104 1
Screen EQOL0105 2
Screen PGIS	2
Screen CGIS 3
Week4 EQOL0101 2
Week4 EQOL0102 4
Week4 EQOL0103 3
Week4 EQOL0104 1
Week4 EQOL0105 2
Week4 PGIS	1
Week4 CGIS 2
Week4 PGIC	1
Week4 CGIC 2
Week8 EQOL0101 2
Week8 EQOL0102 4
Week8 EQOL0103 3
Week8 EQOL0104 1
Week8 EQOL0105 2
Week8 PGIS	1
Week8 CGIS 2
Week8 PGIC	1
Week8 CGIC 2
;
run; 

proc report data=have;
	column visit gr paramcd aval;
	define visit/ order noprint;
	define gr/ order noprint;
	define paramcd/ 'Item' display;
	define aval/'Value' display;
	compute before visit/style={just=c};
		line @1 text $40.;
		length text $40;
		if visit='Screen' then text='Screening';
		else if visit='Week4' then text= 'Week 4';
		else if visit='Week8' then text='Week 8';
	endcomp;
	compute before gr;
		line @1 text $40.;
		length text $40;
		if gr=2 then text='EQ-5D-5L';
	endcomp; 
run; 

Result:
Capture.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Or you could try data _null_; suggest to use format $varying.

 




proc report data=have nowd;
	column visit gr paramcd aval;
	define visit/ order noprint;
	define gr/ order noprint;
	define paramcd/ 'Item' display;
	define aval/'Value' display;
	compute before visit/style={just=c};
		line @1 text $40.;
		length text $40;
		if visit='Screen' then text='Screening';
		else if visit='Week4' then text= 'Week 4';
		else if visit='Week8' then text='Week 8';
	endcomp;
	compute before gr;
		line @1 text $varying40. len;
		length text $ 40;
		len=0;
		if gr=2 then do;len=10;text='EQ-5D-5L';end;
	endcomp; 
run; 

Ksharp_0-1716617320523.png

 

View solution in original post

5 REPLIES 5
Ksharp
Super User

You used TWO 'line' statement in two different computed blocks. Just combine these two computed blocks into ONE .

 


proc report data=have;
	column visit gr paramcd aval;
	define visit/ order noprint;
	define gr/ order noprint;
	define paramcd/ 'Item' display;
	define aval/'Value' display;
	compute before gr;
		line @1 text $40.;
		length text $40;

		if visit='Screen' then text='Screening';
		else if visit='Week4' then text= 'Week 4';
		else if visit='Week8' then text='Week 8';

		if gr=2 then text='EQ-5D-5L';
	endcomp; 
run; 
A_Kh
Lapis Lazuli | Level 10

Hi @Ksharp , 
Thank you for the suggestion. Interesting, VISIT is also a grouping variable that is handled inside another grouping variable GR. This eliminated the unnecessary extra row. Could we also keep the original justification of text in the report?  VISITs are centered, GR is left justified. I tried with ods escapechar style elements, it didn't help. 

ods escapechar='~';
proc report data=have;
	column visit gr paramcd aval;
	define visit/ order noprint;
	define gr/ order noprint;
	define paramcd/ 'Item' display;
	define aval/'Value' display;
	compute before gr/style={just=c};
		line @1 text $40.;
		length text $40;

		if visit='Screen' then text='Screening';
		else if visit='Week4' then text= 'Week 4';
		else if visit='Week8' then text='Week 8';

		if gr=2 then text="~S={just=left} EQ-5D-5L";
	endcomp; 
run; 
Ksharp
Super User

Or you could try data _null_; suggest to use format $varying.

 




proc report data=have nowd;
	column visit gr paramcd aval;
	define visit/ order noprint;
	define gr/ order noprint;
	define paramcd/ 'Item' display;
	define aval/'Value' display;
	compute before visit/style={just=c};
		line @1 text $40.;
		length text $40;
		if visit='Screen' then text='Screening';
		else if visit='Week4' then text= 'Week 4';
		else if visit='Week8' then text='Week 8';
	endcomp;
	compute before gr;
		line @1 text $varying40. len;
		length text $ 40;
		len=0;
		if gr=2 then do;len=10;text='EQ-5D-5L';end;
	endcomp; 
run; 

Ksharp_0-1716617320523.png

 

A_Kh
Lapis Lazuli | Level 10

Thank you @Ksharp  for taking the time to look into the documentation and applying $varying format in my example.!

Very grateful to @data_null__ for the precious tips and guidance!

Appreciate your help, guys!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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
  • 5 replies
  • 480 views
  • 5 likes
  • 3 in conversation