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

Hi All,

 

I'm trying to use Attrmap and a proc format but they seem to cancel each other over.

 

If I run the code without the format Simplification typeFmt. I get the green from the Attrmap - as expected -  and legend = 0 (pic 1).

 

If I run with format Simplification typeFmt. I loose the formatting from Attrmap and the legend   = Pre trial (pic2) 

 

Is there a way I can have both  - Attrmap and the proc format work together. Green columns from the Attrmap and a legend shows Pre trial and Post Trial. 

 

 

Data Attrmap;
	Retain id "myid";
	input value $ fillcolor $8.;
	datalines;
	0 VIBG
	1 BIBG
	;
run;

proc format;
	value typeFmt
		0 = "Pre Trial"
		1 = "Post Trial" 
	;
	ods graphics on / width=9in height=5in;

Proc SGPLOT data=work.DSCMax noborder dattrmap=attrmap;
	*/
	format Simplification typeFmt.;
	VBAR EVENT_DT / Response=Max_answer_tm Group=Simplification attrid=myid nooutline seglabel seglabelattrs=(weight=Bold color=WHITE size=8 );
	yaxis display=(noline noticks) grid values=(0 to 3600 by 300) offsetmin=0 label='mm:ss';
RUN;

ODS graphics OFF;

 

Apologies if the test data doesn't run - this is what it looks like though

data test;
	Input CD EVENT_DT Group Simplification MAX_ANSWER_TM;
	Datalines;
TSDa 	2018-07-06	DSC	0	38:21
TSDa	2018-07-09	DSC	0	9:41
TSDa	2018-07-10	DSC	0	23:31
TSDa	2018-07-11	DSC	0	14:47
TSDa	2018-07-12	DSC	0	17:40
TSDa	2018-07-13	DSC	0	20:34
TSDa	2018-07-16	DSC	0	8:55
TSDa	2018-07-17	DSC	0	22:17
TSDa	2018-07-18	DSC	0	16:42
TSDa	2018-07-19	DSC	0	10:31
TSDa	2018-07-20	DSC	0	11:12
TSDa	2018-07-23	DSC	0	10:13
TSDa	2018-07-24	DSC	0	6:37
TSDa	2018-07-25	DSC	0	17:00
TSDa	2018-07-26	DSC	0	7:11
TSDa	2018-07-27	DSC	0	10:43
;
RUN;

Pic 1                                                                                                 Pic 2

Capture1.JPGCapture2.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @DME790,

 

According to the documentation: "If the group value is formatted, then the text-string in the attribute map data set must contain the formatted value."

 

So, just modify variable VALUE in dataset ATTRMAP:

data test;
input cd $ event_dt :yymmdd. group $ Simplification max_answer_tm :time.;
max_answer_tm=max_answer_tm/60;
format event_dt yymmdd10. max_answer_tm mmss.;
label event_dt='Event Date';
datalines;
TSDa 2018-07-06 DSC 0 38:21
TSDa 2018-07-09 DSC 0 9:41
TSDa 2018-07-10 DSC 0 23:31
TSDa 2018-07-11 DSC 0 14:47
TSDa 2018-07-12 DSC 0 17:40
TSDa 2018-07-13 DSC 0 20:34
TSDa 2018-07-16 DSC 0 8:55
TSDa 2018-07-17 DSC 0 22:17
TSDa 2018-07-18 DSC 0 16:42
TSDa 2018-07-19 DSC 0 10:31
TSDa 2018-07-20 DSC 0 11:12
TSDa 2018-07-23 DSC 0 10:13
TSDa 2018-07-24 DSC 0 6:37
TSDa 2018-07-25 DSC 0 17:00
TSDa 2018-07-26 DSC 0 7:11
TSDa 2018-07-27 DSC 0 10:43
TSDa 2018-07-27 DSC 1 -0:01
; /* last obs. added to force "Post Trial" into the legend */

data attrmap;
retain id "myid";
input value :&$10. fillcolor $8.;
datalines;
Pre Trial   VIBG
Post Trial  BIBG
;

ods graphics on / width=9in height=5in;

proc sgplot data=test noborder dattrmap=attrmap;
format Simplification typeFmt.;
vbar event_dt / response=max_answer_tm group=Simplification attrid=myid nooutline seglabel seglabelattrs=(weight=bold color=white size=8 );
yaxis display=(noline noticks) grid values=(0 to 3600 by 300) offsetmin=0 label='mm:ss';
run;

ods graphics off;

If you don't need "Post Trial" in the legend if only "Pre Trial" values occur in the graph, just delete the dummy observation that I've added.

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hi @DME790,

 

According to the documentation: "If the group value is formatted, then the text-string in the attribute map data set must contain the formatted value."

 

So, just modify variable VALUE in dataset ATTRMAP:

data test;
input cd $ event_dt :yymmdd. group $ Simplification max_answer_tm :time.;
max_answer_tm=max_answer_tm/60;
format event_dt yymmdd10. max_answer_tm mmss.;
label event_dt='Event Date';
datalines;
TSDa 2018-07-06 DSC 0 38:21
TSDa 2018-07-09 DSC 0 9:41
TSDa 2018-07-10 DSC 0 23:31
TSDa 2018-07-11 DSC 0 14:47
TSDa 2018-07-12 DSC 0 17:40
TSDa 2018-07-13 DSC 0 20:34
TSDa 2018-07-16 DSC 0 8:55
TSDa 2018-07-17 DSC 0 22:17
TSDa 2018-07-18 DSC 0 16:42
TSDa 2018-07-19 DSC 0 10:31
TSDa 2018-07-20 DSC 0 11:12
TSDa 2018-07-23 DSC 0 10:13
TSDa 2018-07-24 DSC 0 6:37
TSDa 2018-07-25 DSC 0 17:00
TSDa 2018-07-26 DSC 0 7:11
TSDa 2018-07-27 DSC 0 10:43
TSDa 2018-07-27 DSC 1 -0:01
; /* last obs. added to force "Post Trial" into the legend */

data attrmap;
retain id "myid";
input value :&$10. fillcolor $8.;
datalines;
Pre Trial   VIBG
Post Trial  BIBG
;

ods graphics on / width=9in height=5in;

proc sgplot data=test noborder dattrmap=attrmap;
format Simplification typeFmt.;
vbar event_dt / response=max_answer_tm group=Simplification attrid=myid nooutline seglabel seglabelattrs=(weight=bold color=white size=8 );
yaxis display=(noline noticks) grid values=(0 to 3600 by 300) offsetmin=0 label='mm:ss';
run;

ods graphics off;

If you don't need "Post Trial" in the legend if only "Pre Trial" values occur in the graph, just delete the dummy observation that I've added.

DME790
Pyrite | Level 9

Thanks @FreelanceReinh

 

Works a treat

 

Cheers

 

Dean

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1800 views
  • 1 like
  • 2 in conversation