The SAS Output Delivery System and reporting techniques

Concatenate Variables in proc report

Reply
Regular Contributor
Regular Contributor
Posts: 166

Concatenate Variables in proc report

Guys,
Is it possible for a computed variable in proc report to have the concatenated values of two other variables.


DATA A;
XC='XXX';
XB='YYY';
RUN;

PROC REPORT DATA=A;
COLUMN XC XB NAME;
DEFINE XC / DISPLAY;
DEFINE XB / DISPLAY;
define xcc / computed;
define xbb / computed;
DEFINE NAME / COMPUTED;

COMPUTE NAME;
NAME = XC || XB;
ENDCOMP;
RUN;

What i am looking for is that my vaible NAME should be "XXX YYY". in the report.

PLZ suggest
Regular Contributor
Posts: 229

Re: Concatenate Variables in proc report

I had the same problem.

Just make a variable in your data set A which concats the two, and display that var?
SAS Super FREQ
Posts: 8,740

Re: Concatenate Variables in proc report

Hi:
I'm confused...what do you want to CREATE??? NAME, XBB or XCC??? I am guessing that you are getting a message like this:
[pre]
NOTE: Invalid numeric data, 'XXXYYY' , at line 1 column 12.
[/pre]

someplace in your log???

When you want/need to compute a character variable, you have to tell PROC REPORT -- normally, it wants computed variables to be numeric. The way you tell PROC REPORT is in the COMPUTE block:
[pre]
COMPUTE NAME / CHARACTER length=8;
NAME = trim(xc)||' '||trim(xb);
ENDCOMP;
[/pre]

Do note that the length specified should be equal to the longest value for XC plus the longest value for XB plus 1 for the space in between -- I just picked 8 arbitrarily because of your test data -- but your real data may be longer.

Also, you have XBB and XCC in DEFINE Statements, but not in the COLUMN statement -- this should be showing you this warning in the LOG:
[pre]
WARNING: xbb is not in the report definition.
WARNING: xcc is not in the report definition.
[/pre]

and the fix for this is to put these 2 computed items in the COLUMN statement or remove the DEFINE statements if you don't need them once you get NAME working.

cynthia

ps...or you can concatenate the variables ahead of time in a DATA step program.
Super User
Posts: 9,662

Re: Concatenate Variables in proc report

OK. It is easy.


[pre]
ods pdf file='c:\test.pdf' style=journal;
proc report data=sashelp.class nowd ;
column name sex weight merge;
define name /'Name';
define sex /'Sex' ;
define merge/'Name and Sex' computed;
compute merge / character length=100;
merge=cats(name,sex);
endcomp;
run;
ods pdf close;
[/pre]




Ksharp Message was edited by: Ksharp
Ask a Question
Discussion stats
  • 3 replies
  • 1694 views
  • 0 likes
  • 4 in conversation