Data visualization with SAS programming

Cupid Arrow with Two Love Heart using SAS EG

Reply
Regular Learner Fan
Regular Learner
Posts: 1

Cupid Arrow with Two Love Heart using SAS EG

I found I cannot post my SAS blogs, in my account, I don't have the options, it is interesting.

I found I can only post questions.

 

%let path = /sas/shared_data/credit_loss_models/MIP_MIS/xx60692/love_heart;;

%let ylabel = Love You To Death;

%let xlabel = Love You To Death;

%let entrylabel = Love You To Death;

%let namelabel = Love You To Death;

%let footnotes = Guaranteed Period: Ten Thousand Years!;

data heart_data1;

do x=-2 to 2 by .05;

y=sqrt(1-(abs(x)-1)**2);

output;

end;

do x=2 to -2 by -.05;

y=arcos(1-abs(x))-3.14;

output;

end;

run;

data heart_data;

set heart_data1;

if y=. then y=0;

if round(x*100)=0 then y=y+.2;

x1=x+0.5;

y1=y;

run;

 

 

data anno_arrow;

x2=-2; y2=-2.5; output;

x2=-.75; y2=-1.25; output;

x2=1; y2=.5; output;

x2=1.75; y2=1.25; output;

run;

data for_heart_data;

retain x y x1 y1 x2 y2;

set heart_data;

y2=0;

if -1.97>x>-2.03 then x2=-2;

if -0.72>x>-0.78 then x2=-0.75;

if -0.49>x>-0.51 then x2=-0.5;

if 0.74>x>0.75 then x2=0.75;

if 1.03>x1>0.97 then x2=1;

if 1.53>x1>1.49 then x3=1.5;

if 1.78>x>1.72 then x3=1.75;

if x2=-2 then y2=-2.5;

if x2=-0.75 then y2=-1.25;

if x2=-0.5 then y2=-1;

if x2=0.75 then y2=0.25;

if x2=1 then y2=.5;

if x3=1.5 then y3=1;

if x3=1.75 then y3=1.25;

if y2=0 then y2=.;

if 0.26<x1<1.24 and y1>0 then y1=.;

if (x1<-0.74 and y>=0) or (x1<0.24 and y<0) then y1=.;

if -0.51 <x2 then y2=.;

if x3< 1.49 then y3=.;

run;

proc sort data=for_heart_data(keep=x3 y3) out=x3y3; by y3; run;

data for_heart;

set for_heart_data(drop=x3 y3); set x3y3;

run;

ods _all_ close; options number nodate;

goptions reset=all device=png gsfname=graphout xpixels=1000 ypixels=400;

ods graphics on/reset imagename="&namelabel." imagefmt=png width=20in height=15in scale=off border=off;

ods listing gpath="&path."; ods path reset;

ODS path (PREPEND) a.TEMPLAT(update);

proc template;

define statgraph a.class; begingraph;

discreteattrvar attrvar=classfill var=fore_sce attrmap='colors';

legendItem type=Line name="x" /lineattrs=(color=red pattern=solid THICKNESS=8) labelattrs=(size=22pt) label="Heart1";

legendItem type=Line name="x1"/lineattrs=(color=red pattern=Solid THICKNESS=8) labelattrs=(size=22pt) label="Heart2";

legendItem type=Line name="x2"/lineattrs=(color=grey pattern=solid THICKNESS=8) labelattrs=(size=22pt) label="Arrow1";

legendItem type=Line name="x3"/lineattrs=(color=grey pattern=solid THICKNESS=8) labelattrs=(size=22pt) label="Arrow2";

layout lattice/border=FALSE BORDERATTRS=(color=white) columns=1 rows=1

COLUMNGUTTER=2cm ROWGUTTER=2cm AUTOALIGN=(TOPRIGHT BOTTOMLEFT) SKIPEMPTYCELLS=TRUE;

cell; cellheader;

entry "&entrylabel."/border=FALSE BORDERATTRS=(color=white) textattrs=(size=50pt weight=bold color=red);

endcellheader;

layout overlay /border=false WALLCOLOR=white WALLDISPLAY=(FILL)

xaxisopts=(display=(label tickvalues) linearopts=(origin=0 THRESHOLDMIN=1 THRESHOLDMAX=1)

label="&xlabel." griddisplay=off labelattrs=(weight=bold size=40pt color=biyg)

tickvalueattrs=(weight=bold size=22pt color=white)

discreteopts=(tickdisplaylist=("-2" "-1.5" "-1" "-0.5" "0" "0.5" "1" "1.5" "2")

tickvaluelist=("-2" "-1.5" "-1" "-0.5" "0" "0.5" "1" "1.5" "2")

 TICKVALUEFITPOLICY=ROTATEALWAYS TICKVALUEROTATION=VERTICAL))

 

yaxisopts=(display=(label tickvalues) label="&ylabel."

labelattrs=(weight=bold size=22pt color=white) griddisplay=off

tickvalueattrs=(weight=bold size=40pt color=white)

linearopts=(integer=FALSE origin=-3 viewmin=-3 tickvalueformat=9.1

tickvaluelist=(-2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5) TICKVALUEPRIORITY=TRUE)

gridattrs=(pattern=dash THICKNESS=2 color=white));

seriesplot x=x y=y /BREAK=TRUE LEGENDLABEL="Heart1" PRIMARY=TRUE lineattrs=(color=red pattern=solid THICKNESS=8);

seriesplot x=x1 y=y1/BREAK=TRUE LEGENDLABEL="Heart2" PRIMARY=TRUE lineattrs=(color=red pattern=MediumDash THICKNESS=8);

seriesplot x=x2 y=y2/BREAK=TRUE LEGENDLABEL="Arrow1" PRIMARY=TRUE lineattrs=(color=grey pattern=solid THICKNESS=20);

seriesplot x=x3 y=y3/BREAK=TRUE LEGENDLABEL="Arrow2" PRIMARY=TRUE lineattrs=(color=grey pattern=solid THICKNESS=20)

ARROWHEADPOSITION=END ARROWHEADSCALE=20 ARROWHEADSHAPE=BARBED;

referenceline y=0/ curvelabel=" " curvelabelattrs=(size=22pt weight=bold color=white)

clip=true curvelabelposition=min lineattrs=(pattern=dash THICKNESS=2 color=white);

endlayout;

endcell;

endlayout;

entryfootnote halign=center TEXTATTRS=(size=35pt weight=bold color=green) "&footnotes.";

layout globallegend/border=false type=COLUMN weights=uniform;

discretelegend "Heart1" "Heart2" "Arrow"/border=false across=1 down=1 autoalign=(CENTER) ORDER=COLUMNMAJOR;

endlayout; endgraph; end; run;

proc sgrender data=for_heart template=a.class; Run;

ods graphics off;

ods listing;

%let path = /sas/shared_data/credit_loss_models/MIP_MIS/xx60692/love_heart;;

%let ylabel     = Love You To Death;
%let xlabel     = Love You To Death;
%let entrylabel = Love You To Death;
%let namelabel  = Love You To Death;
%let footnotes  = Guaranteed Period: Ten Thousand Years!;

data heart_data1;
do x=-2 to 2 by .05;
 y=sqrt(1-(abs(x)-1)**2);
 output;
 end;
do x=2 to -2 by -.05;
 y=arcos(1-abs(x))-3.14;
 output;
 end;
run;

data heart_data; 
set  heart_data1;
if y=. then y=0;
if round(x*100)=0 then y=y+.2;
x1=x+0.5;
y1=y;
run;


data anno_arrow;
x2=-2;   y2=-2.5;  output;
x2=-.75; y2=-1.25; output;
x2=1;    y2=.5;    output;
x2=1.75; y2=1.25;  output;
run;

data for_heart_data;
retain x y x1 y1 x2 y2;
set   heart_data;
y2=0;
if -1.97>x>-2.03  then x2=-2; 
if -0.72>x>-0.78  then x2=-0.75; 
if -0.49>x>-0.51  then x2=-0.5;
if 0.74>x>0.75    then x2=0.75;
if 1.03>x1>0.97   then x2=1; 
if 1.53>x1>1.49   then x3=1.5; 
if 1.78>x>1.72    then x3=1.75; 

if x2=-2    then y2=-2.5; 
if x2=-0.75 then y2=-1.25; 
if x2=-0.5  then y2=-1;
if x2=0.75  then y2=0.25;
if x2=1     then y2=.5; 
if x3=1.5   then y3=1; 
if x3=1.75  then y3=1.25; 

if y2=0     then y2=.;
if 0.26<x1<1.24  and y1>0                   then y1=.;
if (x1<-0.74 and y>=0) or (x1<0.24 and y<0) then y1=.;
if -0.51 <x2                                then y2=.;
if        x3< 1.49                          then y3=.;
run;

proc sort data=for_heart_data(keep=x3 y3) out=x3y3; by y3; run;

data for_heart;
set for_heart_data(drop=x3 y3); set x3y3;
run;

ods _all_ close; options number nodate;
goptions reset=all device=png gsfname=graphout xpixels=1000 ypixels=400;
ods graphics on/reset imagename="&namelabel." imagefmt=png width=20in height=15in scale=off border=off;
ods listing gpath="&path.";   ods path reset;  
ODS path (PREPEND) a.TEMPLAT(update);

proc template;
define statgraph a.class;    begingraph;   
discreteattrvar attrvar=classfill var=fore_sce attrmap='colors';
legendItem type=Line name="x" /lineattrs=(color=red  pattern=solid THICKNESS=8) labelattrs=(size=22pt) label="Heart1"; 
legendItem type=Line name="x1"/lineattrs=(color=red  pattern=Solid THICKNESS=8) labelattrs=(size=22pt) label="Heart2"; 
legendItem type=Line name="x2"/lineattrs=(color=grey pattern=solid THICKNESS=8) labelattrs=(size=22pt) label="Arrow1";
legendItem type=Line name="x3"/lineattrs=(color=grey pattern=solid THICKNESS=8) labelattrs=(size=22pt) label="Arrow2";

layout lattice/border=FALSE BORDERATTRS=(color=white) columns=1 rows=1 
  COLUMNGUTTER=2cm ROWGUTTER=2cm AUTOALIGN=(TOPRIGHT BOTTOMLEFT) SKIPEMPTYCELLS=TRUE;

cell; cellheader;    
entry "&entrylabel."/border=FALSE BORDERATTRS=(color=white) textattrs=(size=50pt weight=bold color=red);
endcellheader;

layout overlay /border=false WALLCOLOR=white WALLDISPLAY=(FILL) 
xaxisopts=(display=(label tickvalues) linearopts=(origin=0 THRESHOLDMIN=1 THRESHOLDMAX=1)
   label="&xlabel." griddisplay=off labelattrs=(weight=bold size=40pt color=biyg) 
   tickvalueattrs=(weight=bold size=22pt color=white)
   discreteopts=(tickdisplaylist=("-2" "-1.5" "-1" "-0.5" "0" "0.5" "1" "1.5" "2")
   tickvaluelist=("-2" "-1.5" "-1" "-0.5" "0" "0.5" "1" "1.5" "2") 
   TICKVALUEFITPOLICY=ROTATEALWAYS TICKVALUEROTATION=VERTICAL))

yaxisopts=(display=(label tickvalues) label="&ylabel." 
   labelattrs=(weight=bold size=22pt color=white) griddisplay=off 
   tickvalueattrs=(weight=bold size=40pt color=white) 
   linearopts=(integer=FALSE origin=-3 viewmin=-3 tickvalueformat=9.1 
   tickvaluelist=(-2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5) TICKVALUEPRIORITY=TRUE) 
   gridattrs=(pattern=dash THICKNESS=2 color=white));

seriesplot x=x  y=y /BREAK=TRUE LEGENDLABEL="Heart1" PRIMARY=TRUE lineattrs=(color=red  pattern=solid  THICKNESS=8); 
seriesplot x=x1 y=y1/BREAK=TRUE LEGENDLABEL="Heart2" PRIMARY=TRUE lineattrs=(color=red  pattern=MediumDash THICKNESS=8); 
seriesplot x=x2 y=y2/BREAK=TRUE LEGENDLABEL="Arrow1" PRIMARY=TRUE lineattrs=(color=grey pattern=solid THICKNESS=20); 
seriesplot x=x3 y=y3/BREAK=TRUE LEGENDLABEL="Arrow2" PRIMARY=TRUE lineattrs=(color=grey pattern=solid THICKNESS=20) 
                     ARROWHEADPOSITION=END ARROWHEADSCALE=20 ARROWHEADSHAPE=BARBED;

referenceline y=0/ curvelabel=" " curvelabelattrs=(size=22pt weight=bold color=white) 
  clip=true curvelabelposition=min lineattrs=(pattern=dash THICKNESS=2 color=white);

endlayout; 
endcell;

endlayout;  
entryfootnote halign=center  TEXTATTRS=(size=35pt weight=bold color=green) "&footnotes."; 

layout globallegend/border=false type=COLUMN weights=uniform;
discretelegend "Heart1" "Heart2" "Arrow"/border=false across=1 down=1 autoalign=(CENTER) ORDER=COLUMNMAJOR;
endlayout;  endgraph; end; run;

proc sgrender data=for_heart template=a.class;  Run; 
ods graphics off;  
ods listing;

Love You To Death.png

 

Attachment
Community Manager
Posts: 3,362

Re: Cupid Arrow with Two Love Heart using SAS EG

Hi @Fan, I added you to the "author" role, so you can now create a library article with your example, if you want.  Here are the instructions.

Ask a Question
Discussion stats
  • 1 reply
  • 121 views
  • 1 like
  • 2 in conversation