BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kenan
Calcite | Level 5

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

            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!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

4 REPLIES 4
ballardw
Super User

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.

Kenan
Calcite | Level 5

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;

 

 

ballardw
Super User

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.

Kenan
Calcite | Level 5

THanks ALot. That works!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1300 views
  • 0 likes
  • 2 in conversation