BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi
i have a query in proc report.
i am struggling to get the following output.
i have to display the following column in proc report as group a group variable.
i have concatenated variable of age,race,sex. then how can i display that concatenated variable below subject Id in the same cell. and this is to be grouped.

SubjectID type
(Age/sex/race)

1 x
(56/male/white)
y

2
(58/female/black) x
y
1 REPLY 1
Cynthia_sas
Diamond | Level 26
Hi,
Through the use of ODS ESCAPECHAR, you can introduce a "line break" character into your output file. In the program sample below, the ESCAPECHAR that I use is the tilde (~). Note how the tilde is used in the DATA step program where the variable values are concatenated. Then, the ESCAPECHAR is declared in the ODS ESCAPECHAR statement inside my ODS "sandwich":
[pre]
data newclass;
set sashelp.class;
length strvar $100;
strvar = trim(name)||'~n('||
trim(put(age,2.0))||' '||right(put(height,5.1))||')'||
'~n'||'stuff';
run;

ods html file='stackvals.html' style=sasweb;
ods rtf file='stackvals.rtf';
ods pdf file='stackvals.pdf';
ods escapechar = '~';
proc report data=newclass nowd
style(header)={vjust=b};
column strvar name age height;
define strvar / order 'Name~n(Age Height)~nOther'
style(header)={just=l}
style(column)={cellwidth=1in};
define name / order 'Name Only';
define age / display 'Age Only';
define Height / display 'Height Only' f=5.1;
run;
ods _all_ close;
[/pre]

The cellwidth=1in was needed on my system because otherwise Word broke the string for Age and Height between the two values. You do not say how you concatentated the variable values. It is possible to do the concatenation in PROC REPORT, also, but that approach, while more efficient because it makes one pass through the data, is also more complicated because of your requirement to group on the concatenated field. If you are interested in pursuing the second approach, I recommend reading the HELP topics:
The REPORT Procedure --> Concepts: REPORT Procedure
The REPORT Procedure --> How PROC REPORT Builds a Report
OR contacting Tech Support for further help.

cynthia

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
  • 1 reply
  • 876 views
  • 0 likes
  • 2 in conversation