SAS sgplot step color gradient












1















I want to generate a "step" plot (CDF) and I'm trying to change the line color using the dattrmap option. But color are not changing. Below is my code:



%MACRO ATRRMAP(fich=,var=);
proc freq data=&fich noprint;
tables &var/nocum nopercent norow nocol out=freq&var;
format _all_;
where &var^=.;
run;
data test;
set freq&var end=eof;
call symputx("mvCAT"||strip(_N_),&var);
if eof then call symputx("NB",_N_);
run;
data myattrmap;
length id $20 value 3 linecolor $10 pattern 3 fillcolor $20;
%do i=1 %to &NB;
id='myid';
value = &&mvCAT&i;
linecolor=cats("grey",put(&i*5,hex2.));
%if &i=1 or &i=5 or &i=9 %then %do;
pattern = 1;
%end;%else %if &i=2 or &i=6 or &i=10 %then %do;
pattern = 15;
%end;%else %if &i=3 or &i=7 or &i=11 %then %do;
pattern = 2;
%end;%else %if &i=4 or &i=8 or &i=12 %then %do;
pattern = 8;
%end;%else %do;
pattern = 41;
%end;
fillcolor=cats("grey",put(&i*5,hex2.));
output;
%end;
run;
%MEND ATRRMAP;


The generated data look like the following:



id value pattern fillcolor
myid -6 1 CXbdc3c7
myid -5 2 CXbdc3c7
myid -4 8 CXbdc3c7


Then, I used the sgplot:



PROC SGPLOT DATA=cumul sganno=annotation NOBORDER dattrmap=myattrmap;
STEP X=variable Y=percent/GROUP=newgroup attrid=myid;
YAXIS LABEL="Cumulative percentage of patients" VALUES=(0 TO 100 BY
10);
XAXIS LABEL=" " VALUES=(-4 to 4 by 0.5) ;
KEYLEGEND /TITLE=" " LOCATION=INSIDE POSITION=BOTTOMRIGHT ACROSS=1
DOWN=3 NOBORDER;
RUN;


The data myfile used with sgplot looks like the following:



variable percent newgroup
-3.66 2.70 -6
-3.41 5.40 -6
-3.26 8.11 -6
-3.28 5.8 -5
-2.97 13.51 -5


I would like to have a grey gradient. But first, I would simply like to choose, with dattrmap, color lines on my plot. I try with fillcolor and linecolor but it did not work. I try to change the color directly in the SGPLOT statement with the datacontrastcolors option of styleattrs and it works. Does someone see what am I missing ?










share|improve this question

























  • Where's the macro call, with the parameters?

    – Reeza
    Nov 19 '18 at 16:22











  • @Reeza Here is the attrmap macro call: '%ATRRMAP(fich=myfile,var=myvar);'

    – Appyface
    Nov 19 '18 at 16:24











  • Add that and some sample data to your post and we can test it and see where it's going wrong. Data attribute maps do work. Sometimes you need to set attrpriority=none option on the ODS GRAPHICS statement though to force it to override the defaults.

    – Reeza
    Nov 19 '18 at 16:27











  • Thanks @Reeza, I updated my post with some datalines. Also, I try the attrpriority option but it didn't work :/

    – Appyface
    Nov 19 '18 at 16:56











  • For some reason your code converts value to a character value. Are you having that happen as well? That could be your issue.

    – Reeza
    Nov 19 '18 at 17:51
















1















I want to generate a "step" plot (CDF) and I'm trying to change the line color using the dattrmap option. But color are not changing. Below is my code:



%MACRO ATRRMAP(fich=,var=);
proc freq data=&fich noprint;
tables &var/nocum nopercent norow nocol out=freq&var;
format _all_;
where &var^=.;
run;
data test;
set freq&var end=eof;
call symputx("mvCAT"||strip(_N_),&var);
if eof then call symputx("NB",_N_);
run;
data myattrmap;
length id $20 value 3 linecolor $10 pattern 3 fillcolor $20;
%do i=1 %to &NB;
id='myid';
value = &&mvCAT&i;
linecolor=cats("grey",put(&i*5,hex2.));
%if &i=1 or &i=5 or &i=9 %then %do;
pattern = 1;
%end;%else %if &i=2 or &i=6 or &i=10 %then %do;
pattern = 15;
%end;%else %if &i=3 or &i=7 or &i=11 %then %do;
pattern = 2;
%end;%else %if &i=4 or &i=8 or &i=12 %then %do;
pattern = 8;
%end;%else %do;
pattern = 41;
%end;
fillcolor=cats("grey",put(&i*5,hex2.));
output;
%end;
run;
%MEND ATRRMAP;


The generated data look like the following:



id value pattern fillcolor
myid -6 1 CXbdc3c7
myid -5 2 CXbdc3c7
myid -4 8 CXbdc3c7


Then, I used the sgplot:



PROC SGPLOT DATA=cumul sganno=annotation NOBORDER dattrmap=myattrmap;
STEP X=variable Y=percent/GROUP=newgroup attrid=myid;
YAXIS LABEL="Cumulative percentage of patients" VALUES=(0 TO 100 BY
10);
XAXIS LABEL=" " VALUES=(-4 to 4 by 0.5) ;
KEYLEGEND /TITLE=" " LOCATION=INSIDE POSITION=BOTTOMRIGHT ACROSS=1
DOWN=3 NOBORDER;
RUN;


The data myfile used with sgplot looks like the following:



variable percent newgroup
-3.66 2.70 -6
-3.41 5.40 -6
-3.26 8.11 -6
-3.28 5.8 -5
-2.97 13.51 -5


I would like to have a grey gradient. But first, I would simply like to choose, with dattrmap, color lines on my plot. I try with fillcolor and linecolor but it did not work. I try to change the color directly in the SGPLOT statement with the datacontrastcolors option of styleattrs and it works. Does someone see what am I missing ?










share|improve this question

























  • Where's the macro call, with the parameters?

    – Reeza
    Nov 19 '18 at 16:22











  • @Reeza Here is the attrmap macro call: '%ATRRMAP(fich=myfile,var=myvar);'

    – Appyface
    Nov 19 '18 at 16:24











  • Add that and some sample data to your post and we can test it and see where it's going wrong. Data attribute maps do work. Sometimes you need to set attrpriority=none option on the ODS GRAPHICS statement though to force it to override the defaults.

    – Reeza
    Nov 19 '18 at 16:27











  • Thanks @Reeza, I updated my post with some datalines. Also, I try the attrpriority option but it didn't work :/

    – Appyface
    Nov 19 '18 at 16:56











  • For some reason your code converts value to a character value. Are you having that happen as well? That could be your issue.

    – Reeza
    Nov 19 '18 at 17:51














1












1








1








I want to generate a "step" plot (CDF) and I'm trying to change the line color using the dattrmap option. But color are not changing. Below is my code:



%MACRO ATRRMAP(fich=,var=);
proc freq data=&fich noprint;
tables &var/nocum nopercent norow nocol out=freq&var;
format _all_;
where &var^=.;
run;
data test;
set freq&var end=eof;
call symputx("mvCAT"||strip(_N_),&var);
if eof then call symputx("NB",_N_);
run;
data myattrmap;
length id $20 value 3 linecolor $10 pattern 3 fillcolor $20;
%do i=1 %to &NB;
id='myid';
value = &&mvCAT&i;
linecolor=cats("grey",put(&i*5,hex2.));
%if &i=1 or &i=5 or &i=9 %then %do;
pattern = 1;
%end;%else %if &i=2 or &i=6 or &i=10 %then %do;
pattern = 15;
%end;%else %if &i=3 or &i=7 or &i=11 %then %do;
pattern = 2;
%end;%else %if &i=4 or &i=8 or &i=12 %then %do;
pattern = 8;
%end;%else %do;
pattern = 41;
%end;
fillcolor=cats("grey",put(&i*5,hex2.));
output;
%end;
run;
%MEND ATRRMAP;


The generated data look like the following:



id value pattern fillcolor
myid -6 1 CXbdc3c7
myid -5 2 CXbdc3c7
myid -4 8 CXbdc3c7


Then, I used the sgplot:



PROC SGPLOT DATA=cumul sganno=annotation NOBORDER dattrmap=myattrmap;
STEP X=variable Y=percent/GROUP=newgroup attrid=myid;
YAXIS LABEL="Cumulative percentage of patients" VALUES=(0 TO 100 BY
10);
XAXIS LABEL=" " VALUES=(-4 to 4 by 0.5) ;
KEYLEGEND /TITLE=" " LOCATION=INSIDE POSITION=BOTTOMRIGHT ACROSS=1
DOWN=3 NOBORDER;
RUN;


The data myfile used with sgplot looks like the following:



variable percent newgroup
-3.66 2.70 -6
-3.41 5.40 -6
-3.26 8.11 -6
-3.28 5.8 -5
-2.97 13.51 -5


I would like to have a grey gradient. But first, I would simply like to choose, with dattrmap, color lines on my plot. I try with fillcolor and linecolor but it did not work. I try to change the color directly in the SGPLOT statement with the datacontrastcolors option of styleattrs and it works. Does someone see what am I missing ?










share|improve this question
















I want to generate a "step" plot (CDF) and I'm trying to change the line color using the dattrmap option. But color are not changing. Below is my code:



%MACRO ATRRMAP(fich=,var=);
proc freq data=&fich noprint;
tables &var/nocum nopercent norow nocol out=freq&var;
format _all_;
where &var^=.;
run;
data test;
set freq&var end=eof;
call symputx("mvCAT"||strip(_N_),&var);
if eof then call symputx("NB",_N_);
run;
data myattrmap;
length id $20 value 3 linecolor $10 pattern 3 fillcolor $20;
%do i=1 %to &NB;
id='myid';
value = &&mvCAT&i;
linecolor=cats("grey",put(&i*5,hex2.));
%if &i=1 or &i=5 or &i=9 %then %do;
pattern = 1;
%end;%else %if &i=2 or &i=6 or &i=10 %then %do;
pattern = 15;
%end;%else %if &i=3 or &i=7 or &i=11 %then %do;
pattern = 2;
%end;%else %if &i=4 or &i=8 or &i=12 %then %do;
pattern = 8;
%end;%else %do;
pattern = 41;
%end;
fillcolor=cats("grey",put(&i*5,hex2.));
output;
%end;
run;
%MEND ATRRMAP;


The generated data look like the following:



id value pattern fillcolor
myid -6 1 CXbdc3c7
myid -5 2 CXbdc3c7
myid -4 8 CXbdc3c7


Then, I used the sgplot:



PROC SGPLOT DATA=cumul sganno=annotation NOBORDER dattrmap=myattrmap;
STEP X=variable Y=percent/GROUP=newgroup attrid=myid;
YAXIS LABEL="Cumulative percentage of patients" VALUES=(0 TO 100 BY
10);
XAXIS LABEL=" " VALUES=(-4 to 4 by 0.5) ;
KEYLEGEND /TITLE=" " LOCATION=INSIDE POSITION=BOTTOMRIGHT ACROSS=1
DOWN=3 NOBORDER;
RUN;


The data myfile used with sgplot looks like the following:



variable percent newgroup
-3.66 2.70 -6
-3.41 5.40 -6
-3.26 8.11 -6
-3.28 5.8 -5
-2.97 13.51 -5


I would like to have a grey gradient. But first, I would simply like to choose, with dattrmap, color lines on my plot. I try with fillcolor and linecolor but it did not work. I try to change the color directly in the SGPLOT statement with the datacontrastcolors option of styleattrs and it works. Does someone see what am I missing ?







colors sas cdf step sgplot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 12:52







Appyface

















asked Nov 19 '18 at 16:20









AppyfaceAppyface

124




124













  • Where's the macro call, with the parameters?

    – Reeza
    Nov 19 '18 at 16:22











  • @Reeza Here is the attrmap macro call: '%ATRRMAP(fich=myfile,var=myvar);'

    – Appyface
    Nov 19 '18 at 16:24











  • Add that and some sample data to your post and we can test it and see where it's going wrong. Data attribute maps do work. Sometimes you need to set attrpriority=none option on the ODS GRAPHICS statement though to force it to override the defaults.

    – Reeza
    Nov 19 '18 at 16:27











  • Thanks @Reeza, I updated my post with some datalines. Also, I try the attrpriority option but it didn't work :/

    – Appyface
    Nov 19 '18 at 16:56











  • For some reason your code converts value to a character value. Are you having that happen as well? That could be your issue.

    – Reeza
    Nov 19 '18 at 17:51



















  • Where's the macro call, with the parameters?

    – Reeza
    Nov 19 '18 at 16:22











  • @Reeza Here is the attrmap macro call: '%ATRRMAP(fich=myfile,var=myvar);'

    – Appyface
    Nov 19 '18 at 16:24











  • Add that and some sample data to your post and we can test it and see where it's going wrong. Data attribute maps do work. Sometimes you need to set attrpriority=none option on the ODS GRAPHICS statement though to force it to override the defaults.

    – Reeza
    Nov 19 '18 at 16:27











  • Thanks @Reeza, I updated my post with some datalines. Also, I try the attrpriority option but it didn't work :/

    – Appyface
    Nov 19 '18 at 16:56











  • For some reason your code converts value to a character value. Are you having that happen as well? That could be your issue.

    – Reeza
    Nov 19 '18 at 17:51

















Where's the macro call, with the parameters?

– Reeza
Nov 19 '18 at 16:22





Where's the macro call, with the parameters?

– Reeza
Nov 19 '18 at 16:22













@Reeza Here is the attrmap macro call: '%ATRRMAP(fich=myfile,var=myvar);'

– Appyface
Nov 19 '18 at 16:24





@Reeza Here is the attrmap macro call: '%ATRRMAP(fich=myfile,var=myvar);'

– Appyface
Nov 19 '18 at 16:24













Add that and some sample data to your post and we can test it and see where it's going wrong. Data attribute maps do work. Sometimes you need to set attrpriority=none option on the ODS GRAPHICS statement though to force it to override the defaults.

– Reeza
Nov 19 '18 at 16:27





Add that and some sample data to your post and we can test it and see where it's going wrong. Data attribute maps do work. Sometimes you need to set attrpriority=none option on the ODS GRAPHICS statement though to force it to override the defaults.

– Reeza
Nov 19 '18 at 16:27













Thanks @Reeza, I updated my post with some datalines. Also, I try the attrpriority option but it didn't work :/

– Appyface
Nov 19 '18 at 16:56





Thanks @Reeza, I updated my post with some datalines. Also, I try the attrpriority option but it didn't work :/

– Appyface
Nov 19 '18 at 16:56













For some reason your code converts value to a character value. Are you having that happen as well? That could be your issue.

– Reeza
Nov 19 '18 at 17:51





For some reason your code converts value to a character value. Are you having that happen as well? That could be your issue.

– Reeza
Nov 19 '18 at 17:51












1 Answer
1






active

oldest

votes


















0














It has to be the GROUP = variable that is the variable that controls the color, shape and patterns. You're grouping your variables by NEWGROUP not the values. You could create a proxy to do this though, if that's what you want. Without some more details of what you need, I'm not sure how we can help you find a work around, but this does explain why it's not working at the moment.



From documentation:




The values of the VALUE variable are valid data group values. These values are case sensitive. The data group is assigned in the plot statement with the GROUP= option.




Assuming you do want the lines different color based on the NEWGROUP here's how you can modify your code. Note that I've simplified your code drastically and there were issues with how you're specifying color - I ignored those for now and am leaving that up to you to fix. The values are currently hard coded in the macro. I would also recommend changing the if _n_ portion to use the MOD() function since you seem to have some sort of pattern in your data. It may not work, but worth considering.



*create fake data;
data myfile;
input variable percent newgroup $;
cards;
-3.66 2.70 group1
-3.41 5.40 group1
-3.26 8.11 group1
-3.28 5.8 group2
-2.97 13.51 group2
;;;;
run;

*macro to create attribute map;
%MACRO ATRRMAP(fich=,var=);

proc freq data=&fich noprint;
tables &var/nocum nopercent norow nocol out=freq&var (drop=percent);
format _all_;
where not missing(&var);
run;

data myattrmap;
length id $20 value $20 linecolor $10 pattern 3 fillcolor $20;
set freq&var.;
id='myid';
value = &var.;

if _n_ =1 then
linecolor = 'CXbdbdbd';
else if _n_=2 then
linecolor = 'CX636363';

*linecolor=cats("grey",put(_n_*5,hex2.));
if _n_ in (1, 5, 9) then
pattern = 1;
else if _n_ in (2, 6, 10) then
pattern = 15;
else if _n_ in (3, 7, 11) then
pattern = 2;
else if _n_ in ( 4, 8, 12) then
pattern=8;
else pattern = 14;
fillcolor=cats("grey",put(_n_*5,hex2.));
output;
run;

%MEND ATRRMAP;

*create attribute map for newgroup;
%ATRRMAP(fich=myfile, var=newgroup);

*plot graph;
PROC SGPLOT DATA=myfile NOBORDER dattrmap=myattrmap;
STEP X=variable Y=percent/GROUP=newgroup attrid=myid;
YAXIS LABEL="Cumulative percentage of patients" VALUES=(0 TO 100 BY
10);
XAXIS LABEL=" " VALUES=(-4 to 4 by 0.5);
KEYLEGEND /TITLE=" " LOCATION=INSIDE POSITION=BOTTOMRIGHT ACROSS=1
DOWN=3 NOBORDER;
RUN;


Methods & rules for colour scheme names are found here.






share|improve this answer
























  • Thanks @Reeza to giver some thought to my problem. You're right, I want the lines differen color based on the NEWGROUP. I have same values in my data MYFILE and in MYATTRMAP, but it still doesn't work. I will try an another way, thanks!

    – Appyface
    Nov 20 '18 at 12:51











  • The code above works though? It worked on my machine. The color codes being used were part of the problem, I assume you switched to using the Hex codes like I did as well?

    – Reeza
    Nov 20 '18 at 15:26











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378774%2fsas-sgplot-step-color-gradient%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














It has to be the GROUP = variable that is the variable that controls the color, shape and patterns. You're grouping your variables by NEWGROUP not the values. You could create a proxy to do this though, if that's what you want. Without some more details of what you need, I'm not sure how we can help you find a work around, but this does explain why it's not working at the moment.



From documentation:




The values of the VALUE variable are valid data group values. These values are case sensitive. The data group is assigned in the plot statement with the GROUP= option.




Assuming you do want the lines different color based on the NEWGROUP here's how you can modify your code. Note that I've simplified your code drastically and there were issues with how you're specifying color - I ignored those for now and am leaving that up to you to fix. The values are currently hard coded in the macro. I would also recommend changing the if _n_ portion to use the MOD() function since you seem to have some sort of pattern in your data. It may not work, but worth considering.



*create fake data;
data myfile;
input variable percent newgroup $;
cards;
-3.66 2.70 group1
-3.41 5.40 group1
-3.26 8.11 group1
-3.28 5.8 group2
-2.97 13.51 group2
;;;;
run;

*macro to create attribute map;
%MACRO ATRRMAP(fich=,var=);

proc freq data=&fich noprint;
tables &var/nocum nopercent norow nocol out=freq&var (drop=percent);
format _all_;
where not missing(&var);
run;

data myattrmap;
length id $20 value $20 linecolor $10 pattern 3 fillcolor $20;
set freq&var.;
id='myid';
value = &var.;

if _n_ =1 then
linecolor = 'CXbdbdbd';
else if _n_=2 then
linecolor = 'CX636363';

*linecolor=cats("grey",put(_n_*5,hex2.));
if _n_ in (1, 5, 9) then
pattern = 1;
else if _n_ in (2, 6, 10) then
pattern = 15;
else if _n_ in (3, 7, 11) then
pattern = 2;
else if _n_ in ( 4, 8, 12) then
pattern=8;
else pattern = 14;
fillcolor=cats("grey",put(_n_*5,hex2.));
output;
run;

%MEND ATRRMAP;

*create attribute map for newgroup;
%ATRRMAP(fich=myfile, var=newgroup);

*plot graph;
PROC SGPLOT DATA=myfile NOBORDER dattrmap=myattrmap;
STEP X=variable Y=percent/GROUP=newgroup attrid=myid;
YAXIS LABEL="Cumulative percentage of patients" VALUES=(0 TO 100 BY
10);
XAXIS LABEL=" " VALUES=(-4 to 4 by 0.5);
KEYLEGEND /TITLE=" " LOCATION=INSIDE POSITION=BOTTOMRIGHT ACROSS=1
DOWN=3 NOBORDER;
RUN;


Methods & rules for colour scheme names are found here.






share|improve this answer
























  • Thanks @Reeza to giver some thought to my problem. You're right, I want the lines differen color based on the NEWGROUP. I have same values in my data MYFILE and in MYATTRMAP, but it still doesn't work. I will try an another way, thanks!

    – Appyface
    Nov 20 '18 at 12:51











  • The code above works though? It worked on my machine. The color codes being used were part of the problem, I assume you switched to using the Hex codes like I did as well?

    – Reeza
    Nov 20 '18 at 15:26
















0














It has to be the GROUP = variable that is the variable that controls the color, shape and patterns. You're grouping your variables by NEWGROUP not the values. You could create a proxy to do this though, if that's what you want. Without some more details of what you need, I'm not sure how we can help you find a work around, but this does explain why it's not working at the moment.



From documentation:




The values of the VALUE variable are valid data group values. These values are case sensitive. The data group is assigned in the plot statement with the GROUP= option.




Assuming you do want the lines different color based on the NEWGROUP here's how you can modify your code. Note that I've simplified your code drastically and there were issues with how you're specifying color - I ignored those for now and am leaving that up to you to fix. The values are currently hard coded in the macro. I would also recommend changing the if _n_ portion to use the MOD() function since you seem to have some sort of pattern in your data. It may not work, but worth considering.



*create fake data;
data myfile;
input variable percent newgroup $;
cards;
-3.66 2.70 group1
-3.41 5.40 group1
-3.26 8.11 group1
-3.28 5.8 group2
-2.97 13.51 group2
;;;;
run;

*macro to create attribute map;
%MACRO ATRRMAP(fich=,var=);

proc freq data=&fich noprint;
tables &var/nocum nopercent norow nocol out=freq&var (drop=percent);
format _all_;
where not missing(&var);
run;

data myattrmap;
length id $20 value $20 linecolor $10 pattern 3 fillcolor $20;
set freq&var.;
id='myid';
value = &var.;

if _n_ =1 then
linecolor = 'CXbdbdbd';
else if _n_=2 then
linecolor = 'CX636363';

*linecolor=cats("grey",put(_n_*5,hex2.));
if _n_ in (1, 5, 9) then
pattern = 1;
else if _n_ in (2, 6, 10) then
pattern = 15;
else if _n_ in (3, 7, 11) then
pattern = 2;
else if _n_ in ( 4, 8, 12) then
pattern=8;
else pattern = 14;
fillcolor=cats("grey",put(_n_*5,hex2.));
output;
run;

%MEND ATRRMAP;

*create attribute map for newgroup;
%ATRRMAP(fich=myfile, var=newgroup);

*plot graph;
PROC SGPLOT DATA=myfile NOBORDER dattrmap=myattrmap;
STEP X=variable Y=percent/GROUP=newgroup attrid=myid;
YAXIS LABEL="Cumulative percentage of patients" VALUES=(0 TO 100 BY
10);
XAXIS LABEL=" " VALUES=(-4 to 4 by 0.5);
KEYLEGEND /TITLE=" " LOCATION=INSIDE POSITION=BOTTOMRIGHT ACROSS=1
DOWN=3 NOBORDER;
RUN;


Methods & rules for colour scheme names are found here.






share|improve this answer
























  • Thanks @Reeza to giver some thought to my problem. You're right, I want the lines differen color based on the NEWGROUP. I have same values in my data MYFILE and in MYATTRMAP, but it still doesn't work. I will try an another way, thanks!

    – Appyface
    Nov 20 '18 at 12:51











  • The code above works though? It worked on my machine. The color codes being used were part of the problem, I assume you switched to using the Hex codes like I did as well?

    – Reeza
    Nov 20 '18 at 15:26














0












0








0







It has to be the GROUP = variable that is the variable that controls the color, shape and patterns. You're grouping your variables by NEWGROUP not the values. You could create a proxy to do this though, if that's what you want. Without some more details of what you need, I'm not sure how we can help you find a work around, but this does explain why it's not working at the moment.



From documentation:




The values of the VALUE variable are valid data group values. These values are case sensitive. The data group is assigned in the plot statement with the GROUP= option.




Assuming you do want the lines different color based on the NEWGROUP here's how you can modify your code. Note that I've simplified your code drastically and there were issues with how you're specifying color - I ignored those for now and am leaving that up to you to fix. The values are currently hard coded in the macro. I would also recommend changing the if _n_ portion to use the MOD() function since you seem to have some sort of pattern in your data. It may not work, but worth considering.



*create fake data;
data myfile;
input variable percent newgroup $;
cards;
-3.66 2.70 group1
-3.41 5.40 group1
-3.26 8.11 group1
-3.28 5.8 group2
-2.97 13.51 group2
;;;;
run;

*macro to create attribute map;
%MACRO ATRRMAP(fich=,var=);

proc freq data=&fich noprint;
tables &var/nocum nopercent norow nocol out=freq&var (drop=percent);
format _all_;
where not missing(&var);
run;

data myattrmap;
length id $20 value $20 linecolor $10 pattern 3 fillcolor $20;
set freq&var.;
id='myid';
value = &var.;

if _n_ =1 then
linecolor = 'CXbdbdbd';
else if _n_=2 then
linecolor = 'CX636363';

*linecolor=cats("grey",put(_n_*5,hex2.));
if _n_ in (1, 5, 9) then
pattern = 1;
else if _n_ in (2, 6, 10) then
pattern = 15;
else if _n_ in (3, 7, 11) then
pattern = 2;
else if _n_ in ( 4, 8, 12) then
pattern=8;
else pattern = 14;
fillcolor=cats("grey",put(_n_*5,hex2.));
output;
run;

%MEND ATRRMAP;

*create attribute map for newgroup;
%ATRRMAP(fich=myfile, var=newgroup);

*plot graph;
PROC SGPLOT DATA=myfile NOBORDER dattrmap=myattrmap;
STEP X=variable Y=percent/GROUP=newgroup attrid=myid;
YAXIS LABEL="Cumulative percentage of patients" VALUES=(0 TO 100 BY
10);
XAXIS LABEL=" " VALUES=(-4 to 4 by 0.5);
KEYLEGEND /TITLE=" " LOCATION=INSIDE POSITION=BOTTOMRIGHT ACROSS=1
DOWN=3 NOBORDER;
RUN;


Methods & rules for colour scheme names are found here.






share|improve this answer













It has to be the GROUP = variable that is the variable that controls the color, shape and patterns. You're grouping your variables by NEWGROUP not the values. You could create a proxy to do this though, if that's what you want. Without some more details of what you need, I'm not sure how we can help you find a work around, but this does explain why it's not working at the moment.



From documentation:




The values of the VALUE variable are valid data group values. These values are case sensitive. The data group is assigned in the plot statement with the GROUP= option.




Assuming you do want the lines different color based on the NEWGROUP here's how you can modify your code. Note that I've simplified your code drastically and there were issues with how you're specifying color - I ignored those for now and am leaving that up to you to fix. The values are currently hard coded in the macro. I would also recommend changing the if _n_ portion to use the MOD() function since you seem to have some sort of pattern in your data. It may not work, but worth considering.



*create fake data;
data myfile;
input variable percent newgroup $;
cards;
-3.66 2.70 group1
-3.41 5.40 group1
-3.26 8.11 group1
-3.28 5.8 group2
-2.97 13.51 group2
;;;;
run;

*macro to create attribute map;
%MACRO ATRRMAP(fich=,var=);

proc freq data=&fich noprint;
tables &var/nocum nopercent norow nocol out=freq&var (drop=percent);
format _all_;
where not missing(&var);
run;

data myattrmap;
length id $20 value $20 linecolor $10 pattern 3 fillcolor $20;
set freq&var.;
id='myid';
value = &var.;

if _n_ =1 then
linecolor = 'CXbdbdbd';
else if _n_=2 then
linecolor = 'CX636363';

*linecolor=cats("grey",put(_n_*5,hex2.));
if _n_ in (1, 5, 9) then
pattern = 1;
else if _n_ in (2, 6, 10) then
pattern = 15;
else if _n_ in (3, 7, 11) then
pattern = 2;
else if _n_ in ( 4, 8, 12) then
pattern=8;
else pattern = 14;
fillcolor=cats("grey",put(_n_*5,hex2.));
output;
run;

%MEND ATRRMAP;

*create attribute map for newgroup;
%ATRRMAP(fich=myfile, var=newgroup);

*plot graph;
PROC SGPLOT DATA=myfile NOBORDER dattrmap=myattrmap;
STEP X=variable Y=percent/GROUP=newgroup attrid=myid;
YAXIS LABEL="Cumulative percentage of patients" VALUES=(0 TO 100 BY
10);
XAXIS LABEL=" " VALUES=(-4 to 4 by 0.5);
KEYLEGEND /TITLE=" " LOCATION=INSIDE POSITION=BOTTOMRIGHT ACROSS=1
DOWN=3 NOBORDER;
RUN;


Methods & rules for colour scheme names are found here.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 23:50









ReezaReeza

13.2k21227




13.2k21227













  • Thanks @Reeza to giver some thought to my problem. You're right, I want the lines differen color based on the NEWGROUP. I have same values in my data MYFILE and in MYATTRMAP, but it still doesn't work. I will try an another way, thanks!

    – Appyface
    Nov 20 '18 at 12:51











  • The code above works though? It worked on my machine. The color codes being used were part of the problem, I assume you switched to using the Hex codes like I did as well?

    – Reeza
    Nov 20 '18 at 15:26



















  • Thanks @Reeza to giver some thought to my problem. You're right, I want the lines differen color based on the NEWGROUP. I have same values in my data MYFILE and in MYATTRMAP, but it still doesn't work. I will try an another way, thanks!

    – Appyface
    Nov 20 '18 at 12:51











  • The code above works though? It worked on my machine. The color codes being used were part of the problem, I assume you switched to using the Hex codes like I did as well?

    – Reeza
    Nov 20 '18 at 15:26

















Thanks @Reeza to giver some thought to my problem. You're right, I want the lines differen color based on the NEWGROUP. I have same values in my data MYFILE and in MYATTRMAP, but it still doesn't work. I will try an another way, thanks!

– Appyface
Nov 20 '18 at 12:51





Thanks @Reeza to giver some thought to my problem. You're right, I want the lines differen color based on the NEWGROUP. I have same values in my data MYFILE and in MYATTRMAP, but it still doesn't work. I will try an another way, thanks!

– Appyface
Nov 20 '18 at 12:51













The code above works though? It worked on my machine. The color codes being used were part of the problem, I assume you switched to using the Hex codes like I did as well?

– Reeza
Nov 20 '18 at 15:26





The code above works though? It worked on my machine. The color codes being used were part of the problem, I assume you switched to using the Hex codes like I did as well?

– Reeza
Nov 20 '18 at 15:26


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378774%2fsas-sgplot-step-color-gradient%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?