BookmarkSubscribeRSS Feed
Leo9
Quartz | Level 8

Hi All,

I am creating this dataset below to assign different color to bars based on values.  

 

data barcol ;
length id value fillcolor $50 ;
retain linecolor "black" ;
id = "coht"; value = "1 x 10^7 cells" ; fillcolor = "red" ; output;
id = "coht"; value = "2 x 10^8 cells" ; fillcolor = "green" ; output;
id = "coht"; value = "2 x 10^7 cells" ; fillcolor = "orange" ; output;
run;

 

Problem is caret sign (^) is causing an issue when I am using it in proc sgplot (see below). I am getting warning message Duplicate values are not permitted in DiscreteAttrMap: 2 x 10 cells.  

 

It seems it is not considering caret sign (^).   

 

proc sgplot data=final  noautolegend nocycleattrs dattrmap=barcol;
styleattrs wallcolor = lightyellow ;
highlow y=subj low=start high=end1 / highcap=acap group=coht type=bar nooutline nomissinggroup   name = 'proj' attrid = coht ; 

 

Any suggestion on how to make it work? Thanks in advance. 

4 REPLIES 4
Reeza
Super User
Instead of typing out the values, can you get them from your data to avoid the issue? Or try using the ascii code (94) with the BYTE function to get the text as desired.

Maybe this:
value = catt("2 x 10", byte(94), "8 cells";
ballardw
Super User

It may be time to actually provide example data.

With some dummy data this "works"

data barcol ;
length id value fillcolor $50 ;
retain linecolor "black" ;
id = "coht"; value = "1 x 10^7 cells" ; fillcolor = "red" ; output;
id = "coht"; value = "2 x 10^8 cells" ; fillcolor = "green" ; output;
id = "coht"; value = "2 x 10^7 cells" ; fillcolor = "orange" ; output;
run;


data plot;
  infile datalines dlm=',' truncover;
  input subj start end1 coht :$14.;
datalines;
1,5,15,1 x 10^7 cells
2,3,12,2 x 10^8 cells 
3,4,18,2 x 10^7 cells
;

proc sgplot data=plot  noautolegend nocycleattrs dattrmap=barcol;
   styleattrs wallcolor = lightyellow ;
   highlow y=subj low=start high=end1 /  group=coht 
   type=bar nooutline nomissinggroup   name = 'proj' attrid = coht ; 
run;
 

When we say the Value variable has to match the Group variable values you cannot have any difference. From the code you post for the dattrmap set you might have a difference in spaces.

Another potential headache is exactly which character and character set is used for the ^. If one is the programming ^ you get from your keyboard with Shift+6 key that may not be a UNICODE character that looks like it from your data.

 

Run proc contents on both your dattrmap data set and the data set you are plotting.

In this part of the output:

                                      The CONTENTS Procedure

           Data Set Name        WORK.PLOT                     Observations          3
           Member Type          DATA                          Variables             4
           Engine               V9                            Indexes               0
           Created              03/10/2021 14:38:02           Observation Length    40
           Last Modified        03/10/2021 14:38:02           Deleted Observations  0
           Protection                                         Compressed            NO
           Data Set Type                                      Sorted                NO
           Label
           Data Representation  WINDOWS_64
           Encoding             wlatin1  Western (Windows)


If the text following Encoding is not the same you have different characters sets and the equality becomes problematic.

 

Leo9
Quartz | Level 8

I tried both solution but none is working

Reeza
Super User
Show what you tried.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1033 views
  • 0 likes
  • 3 in conversation