BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
unwashedhelimix
Obsidian | Level 7

I have the following code to create a report for a given data:

 

data cutepets;
    length pet $20;  
    input gender $ pet $ number_of_pets;
    cards;
    boy  cockatiel 1
    boy  turtle    3
    boy  rabbit    4
    girl cockatiel 2
    girl turtle    3
    girl rabbit    7
    ;
run;

title "Number of Cute Pets Owned by Families of 3rd Graders";
proc tabulate data=cutepets style=[just=center];
    class gender pet;
    var number_of_pets;

    table gender='Gender', 
          pet='Pet' * number_of_pets='# of Pets' * sum=' ' /
          box=' ' misstext='0';
run;

My output then looks like this:

 

Screenshot 2024-12-02 190633.png

 

How can I color certain cells and add pictures of a cockatiel, rabbit, and turtle? Something like this:

 

Screenshot 2024-12-02 190811.png

 

Can I just add to my proc tabulate to add the colors and the images? Also, how can I move the "# of pets" to the spot in the 2nd output?

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data cutepets;
    length pet $20;  
    input gender $ pet $ number_of_pets;
    cards;
    boy  cockatiel 1
    boy  turtle    3
    boy  rabbit    4
    girl cockatiel 2
    girl turtle    3
    girl rabbit    7
    ;
run;


proc format;
value $ image(default=80)
'cockatiel'='c:\temp\a.png'
'turtle'='c:\temp\b.png'
'rabbit'='c:\temp\c.png'
;
run;


title "Number of Cute Pets Owned by Families of 3rd Graders";
proc tabulate data=cutepets style=[just=center ];
    class gender /style={background=blue color=white};
	class pet /style={background=pink color=white};
    classlev gender /style={background=purple color=white};
	classlev pet /style={background=green color=white postimage=$image80. };

    var number_of_pets;

    table gender='Gender', 
          pet='Pet'* number_of_pets='' * sum=' ' /
          box='# of Pets' misstext='0';
run;

Ksharp_0-1733208512263.png

 

View solution in original post

1 REPLY 1
Ksharp
Super User
data cutepets;
    length pet $20;  
    input gender $ pet $ number_of_pets;
    cards;
    boy  cockatiel 1
    boy  turtle    3
    boy  rabbit    4
    girl cockatiel 2
    girl turtle    3
    girl rabbit    7
    ;
run;


proc format;
value $ image(default=80)
'cockatiel'='c:\temp\a.png'
'turtle'='c:\temp\b.png'
'rabbit'='c:\temp\c.png'
;
run;


title "Number of Cute Pets Owned by Families of 3rd Graders";
proc tabulate data=cutepets style=[just=center ];
    class gender /style={background=blue color=white};
	class pet /style={background=pink color=white};
    classlev gender /style={background=purple color=white};
	classlev pet /style={background=green color=white postimage=$image80. };

    var number_of_pets;

    table gender='Gender', 
          pet='Pet'* number_of_pets='' * sum=' ' /
          box='# of Pets' misstext='0';
run;

Ksharp_0-1733208512263.png

 

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
  • 1 reply
  • 812 views
  • 1 like
  • 2 in conversation