Data visualization with SAS programming

sgplot scatter plot using attrmaps and formats

Reply
Contributor
Posts: 57

sgplot scatter plot using attrmaps and formats

[ Edited ]

I have a question: I wrote this code to plot a graph

proc sgplot data= test dattrmap=attrmap;
where sex=“m“; 
series x=year y=amount /markers group=kind markerattrs=(symbol=circlefilled size=8) 
lineattrs=(pattern=solid thickness=2) attrid=kind;
xaxis values=(2004 to 2014 by 2) display=(nolabel);
yaxis values=(0 to 20 by 5)  label=Amount of exposure' grid;
keylegend/type=marker title= "" valueattrs=(size=8.5) noborder;
run;

I wish to use formats to change the names listed in the legend. but if I add format $test.; to the code

the attrmap doesn't work any more. Is there any way to make this possible?

 

Also I wish to make the y-values in such a way that if I have multiple plots (here using a macro) with different range of values, it automatically make the values from 0 to max by an estimated increment value (which should be determind depending on data range). How is this possible?

my regards

 

SAS Super FREQ
Posts: 1,265

Re: sgplot scatter plot using attrmaps and formats

AttrMap works with formatted values.  So, if you use a character format for the group variable, you must put the formatted values in the attribute map.  Y axis range will automatically adjust for the data.  If you want tick values at a custom intervals, you can provide a large range in the VALUES option, but also use the VALUESHINT option.  This will keep the data range to the amount coming from the data.

Contributor
Posts: 57

Re: sgplot scatter plot using attrmaps and formats

Thanks Sanjay,

but how do I give the format values in attrmap? should I add a column with format and list the corresponding formats, Or add a label

I will be glad if you go into details

SAS Super FREQ
Posts: 1,265

Re: sgplot scatter plot using attrmaps and formats

It is easier if you attach your full program with sample data.

Super User
Posts: 13,084

Re: sgplot scatter plot using attrmaps and formats


@Anita_n wrote:

Thanks Sanjay,

but how do I give the format values in attrmap? should I add a column with format and list the corresponding formats, Or add a label

I will be glad if you go into details


You should have a variable VALUE in you attrmap data set. That value has to match the formatted value of the variable you are using.

 

If the formatted value is "ABC" then the variable value should have the value "ABC" to use the attribute map for the given attribute ID.

 

 

 

Contributor
Posts: 57

Re: sgplot scatter plot using attrmaps and formats

[ Edited ]

@Sanjay_SAS@ballardw: Thanks for your replies,  here are some sample data as you requested

 

the sas code:

proc format;
value $ kind
        mri_a_n= "Occ.males B"
		mri_c_n= "Death males B"
		w_n= "Occ. males L"
		y_n= "Death males L"
		mri_a_m="Occ. females B"
		mri_c_m="Death females B"
		w_m="Occ. females L"
		y_m="Death males L"
; run; proc sgplot data= test.inputdata dattrmap=test.attrmap_test; where sex="m"; format kind $kind.; series x=year y=amount /markers group=kind attrid=kind; xaxis values=(1998 to 2008 by 2) display=(nolabel); yaxis values=(0 to 50 by 5 )label='Amount of exposure' valueshint grid; keylegend/type=marker valueattrs=(size=8.5) noborder; run;

if I add the format "kind" to the code "attrmap" doesnt seem work properly any more. But if I remove the code, it works well.

But I need to apply the format to rename the variables in the legend.

 

My other question is that I need to plot about 50 or more of such graphs using a macro. The xaxis values are quiet fine. For the yaxis,  I have values which have different ranges and intervals depending on the data (but always starts from 0). eg. from 0 to 20 by 5,

from 0 to 10 by 2,  from 0 to 80 by 20, from 0 to 200 by 40, from 0 to 500 by 100 and so on...............

Is there any way to declare this in sgplot?

 

I will be very grateful for any help

Attachment
Attachment
Contributor
Posts: 57

Re: sgplot scatter plot using attrmaps and formats

 I am still counting on any help on this post.

SAS Super FREQ
Posts: 1,265

Re: sgplot scatter plot using attrmaps and formats

From your attrmap_test data set, it seems you are still using the original values in the attrmap.  Instead of "mri_a_n" the value should be the formatted value "Occ.males B" and so on.  These are the values in the legend in the graph.

 

AttrMap.pngGraph.png

Contributor
Posts: 57

Re: sgplot scatter plot using attrmaps and formats

Thanks Sanjay,

I finally solved this problem just as you said, by previously appling the format in a data step to change the variables before using this in the sgplot and it worked fine. For the issue with the xaxis with different ranges and intervals. I defined this in the macro itself, this also worked perfectly. Thanks

 

Ask a Question
Discussion stats
  • 8 replies
  • 196 views
  • 0 likes
  • 3 in conversation