Hi,
I'm have a hidden column in PROC report that I use to create subgroups
Example:
Hidden column Color Price
1 Yellow 20
1 Red 50
2 Green 22
2 black 44
2 orange 123
After Grouping (First column is hidden) the result is:
Color Price
Yellow 20
Red 50
1 $70
Green 22
Black 44
Orange 123
2 189
What I'm trying to add to my proc report is the name of the subgroups: 1 and 2 shown in red above
I have tried but no luck so far.
compute after Color;
call define('hidden column','style','style=Header{pretext="SubTotal " tagattr="Type:String"}');
endcomp;
Appreciate everyone's help!
The first two issues are missing ; to end the Proc Report statement and the Columns statement.
Second is that you want to modify the COLOR column, not the Order.
I would suggest using a different name for you variable Order, perhaps Sequence, just so you can tell where you want to use the variable and where the Proc Report option. May not be critical but odd things do happen when you use keywords as variable names.
How does this look:
data result;
input seq $ Color $ amount;
datalines;
1 Yellow 20
1 Red 50
2 Green 22
2 black 44
2 orange 123
;
proc report data=RESULT;
column seq COLOR AMOUNT ;
define seq / 'ORDER' noprint group order order = DATA group;
define COLOR/ 'COLOR' order order = DATA group ;
define AMOUNT/ 'AMOUNT';
break after seq/ summarize;
compute after seq;
call define('color','style','style=Header{color=red tagattr="Type:String"}');
color = catx(' ',"Group",seq);
endcomp;
run;
The CATX function if not familiar will insert the first character between the strings following, in this case as single space between the word Group and the value of Seq. It strips out leading and trailing spaces from the values and may make "cleaner" text in some circumstances.
Provide the entire Proc Report code. Order of things, such as variable names in the COLUMNS statement, is important in building Proc report. Without seeing all the code it is not really possible to correct things.
Best would be to provide actual example data. "hidden column" is not acceptable as a variable name. If you have variable names with spaces or other funky characters they have to be referenced as name literals. That means there must be an n immediately after the quoted name: "hidden column"n , the quotes could be single or double though.
Thanks for your help!
Here's the real code snippet
proc report data=RESULT
column ORDER COLOR AMOUNT
define ORDER/ 'ORDER' noprint group order order = DATA group;
define COLOR/ 'COLOR' order order = DATA group ;
define AMOUNT/ 'AMOUNT';
break after ORDER/ summarize;
compute after ORDER;
call define('ORDER','style','style=Header{pretext="SubTotal " tagattr="Type:String"}');
endcomp;
run;
The first two issues are missing ; to end the Proc Report statement and the Columns statement.
Second is that you want to modify the COLOR column, not the Order.
I would suggest using a different name for you variable Order, perhaps Sequence, just so you can tell where you want to use the variable and where the Proc Report option. May not be critical but odd things do happen when you use keywords as variable names.
How does this look:
data result;
input seq $ Color $ amount;
datalines;
1 Yellow 20
1 Red 50
2 Green 22
2 black 44
2 orange 123
;
proc report data=RESULT;
column seq COLOR AMOUNT ;
define seq / 'ORDER' noprint group order order = DATA group;
define COLOR/ 'COLOR' order order = DATA group ;
define AMOUNT/ 'AMOUNT';
break after seq/ summarize;
compute after seq;
call define('color','style','style=Header{color=red tagattr="Type:String"}');
color = catx(' ',"Group",seq);
endcomp;
run;
The CATX function if not familiar will insert the first character between the strings following, in this case as single space between the word Group and the value of Seq. It strips out leading and trailing spaces from the values and may make "cleaner" text in some circumstances.
THanks ALot. That works!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.