The SAS Output Delivery System and reporting techniques

Stacking of two variables (one numeric, one char) in proc report

Reply
N/A
Posts: 0

Stacking of two variables (one numeric, one char) in proc report

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
SAS Super FREQ
Posts: 8,866

Re: Stacking of two variables (one numeric, one char) in proc report

Posted in reply to deleted_user
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
Ask a Question
Discussion stats
  • 1 reply
  • 137 views
  • 0 likes
  • 2 in conversation