BookmarkSubscribeRSS Feed
NN
Quartz | Level 8 NN
Quartz | Level 8
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
4 REPLIES 4
Filipvdr
Pyrite | Level 9
I had the same problem.

Just make a variable in your data set A which concats the two, and display that var?
Cynthia_sas
SAS Super FREQ
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.
Rae_
Fluorite | Level 6

Doing something similar but wondering if it's possible to retain the formatting of the columns that you're concatenating so I can have the make with standard formatting the type remain italic as they are when in their own column?  As an example I've used the cars data set to illustrate.

 

data cars;
set sashelp.cars;
run;

    proc freq data=cars;
    table make*type/list out=c1;
    run;

 


ods escape char="~";
proc report data=c1 split='^' style=journal;


column make type final count;

 

define make /display left 'Make' style(column)=[width=10%] ;
define type /left display 'Type' style(column)=[width=10% font_style=italic];
   define final /computed left 'Make, ~S={font_style=italic}Type' style(column)=[width=10%] ;
define count/center display "M(SD) ^ or N(%)" style(column)=[width=10%];

 

compute final /character length=95;
   final=cat(trim(make),", ",left(trim(type)));
endcomp;

 

run;

 

Ksharp
Super User
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 4904 views
  • 0 likes
  • 5 in conversation