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.
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.
I tried both solution but none is working
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.