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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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