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

Hello Community, 

I remember being able to map variable value into LINE statement text in the past, but cannot figure out it now. I believe there is an elementary item that I'm missing (which is unfamiliar to me). 
Currently,  to map a variable value into the LINE I keep hardcoding, eg. using IF/ELSE (see below #1).  Could anyone fix #2 and explain how to avoid hardcoding part? 
Many thanks!

data have;
	input visitnum visit $;
	if visit eq 'Screen' then do score= 1 to 5; output; end; 
	else do score= 1 to 6; output; end; 
	cards;
 1 Screen
 2 Week_1
 3 Week_2
 4 Week_3
;
run; 

proc format;
	value score 1= 'Very severe'
				2= 'Severe'
				3= 'Moderate'
				4= 'Mild'
				5= 'Minimal'
				6= 'No pain';
run; 


/*	1. Current coding */
proc report data=have;
	column visitnum visit score;
	define visitnum/order noprint;
	define visit/ noprint;
	define score/'Response Category' format=score. style(column)={just=l} display;
	compute before visitnum/style={just=l}; 
		line @1 text $40.;
		length text $40;
		if visitnum=1 then text='Screen';
		else if visitnum=2 then text='Week_1';
		else if visitnum=3 then text='Week_2';
		else if visitnum=4 then text='Week_3';
	endcomp; 
run; 

/*	2. Wanted coding - needs to be fixed to get the same result as #1*/
proc report data=have;
	column visitnum visit score;
	define visitnum/order noprint;
	define visit/ noprint;
	define score/'Response Category' format=score. style(column)={just=l} display;
	compute before visitnum/style={just=l}; 
		line @1 text $40.;
		length text $40;
		text=visit;
	endcomp; 
run; 



1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
Diamond | Level 26

Hi, It seems to me, based on your test data that VISITNUM and VISIT are tied together and change at the same time. So if you just change which variable you're using for the COMPUTE BEFORE and make VISIT an ORDER item too, it will greatly simplify your code. I changed the style for the LINE in the COMPUTE block to HEADER, so it was more prominent.

Results:

Cynthia_sas_0-1736991814587.png

 

Alternate code:

/*	ALTERNATE coding */
proc report data=have;
  title 'ALTERNATE coding';
	column visitnum visit score;
	define visitnum/order noprint;
	define visit/ order noprint;
	define score/'Response Category' format=score. style(column)={just=l} display;
	compute before visit/style=Header{just=l}; 
		line @1 visit $40.;
 	endcomp; 
run; 
title;

Cynthia

View solution in original post

4 REPLIES 4
Cynthia_sas
Diamond | Level 26

Hi, It seems to me, based on your test data that VISITNUM and VISIT are tied together and change at the same time. So if you just change which variable you're using for the COMPUTE BEFORE and make VISIT an ORDER item too, it will greatly simplify your code. I changed the style for the LINE in the COMPUTE block to HEADER, so it was more prominent.

Results:

Cynthia_sas_0-1736991814587.png

 

Alternate code:

/*	ALTERNATE coding */
proc report data=have;
  title 'ALTERNATE coding';
	column visitnum visit score;
	define visitnum/order noprint;
	define visit/ order noprint;
	define score/'Response Category' format=score. style(column)={just=l} display;
	compute before visit/style=Header{just=l}; 
		line @1 visit $40.;
 	endcomp; 
run; 
title;

Cynthia

A_Kh
Barite | Level 11

Thank you, Cynthia!
"Header" element is very helpful. 

Ksharp
Super User
data have;
	input visitnum visit $;
	if visit eq 'Screen' then do score= 1 to 5; output; end; 
	else do score= 1 to 6; output; end; 
	cards;
 1 Screen
 2 Week_1
 3 Week_2
 4 Week_3
;
run; 

proc format;
	value score 1= 'Very severe'
				2= 'Severe'
				3= 'Moderate'
				4= 'Mild'
				5= 'Minimal'
				6= 'No pain';

run; 


/*	1. Current coding */
proc report data=have nowd;
	column visitnum visit score;
	define visitnum/order noprint;
	define visit/order noprint;
	define score/'Response Category' format=score. style(column)={just=l} display;
	compute before visit/style={just=l}; 
		line @1 visit $40.;
	endcomp; 
run; 

Ksharp_0-1736992706103.png

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1345 views
  • 3 likes
  • 3 in conversation