Published on :
Reporting CREATION_INTERNE

Biorhythm Chart with SAS/GRAPH

This code is also available in: Deutsch Español Français
Awaiting validation
The script prepares the graphical environment (GOPTIONS), calculates temporal variables related to the current date and the provided birth date (via the &birthdate macro variable), generates sinusoidal data via a DATA step, and plots the resulting curves using PROC GPLOT. It is designed to typically run as a SAS© Stored Process (using _webout).
Data Analysis

Type : CREATION_INTERNE


Data is algorithmically generated in the 'mydata' DATA step by applying sinusoidal functions based on the difference between the current date and the birth date.

1 Code Block
ODS & GOPTIONS
Explanation :
Configuration of ODS HTML output (adapted for Stored Processes) and definition of global graph parameters (size, fonts, colors) with GOPTIONS.
Copied!
1ods listing close;
2ods html body=_webout path=&_tmpcat (url=&_replay) rs=none style=minimal;
3 
4goptions cback=white;
5goptions characters;
6goptions device=png;
7goptions border;
8 
9goptions gunit=pct htitle=5.5 htext=3.5 ctext=gray33 ftitle="albany amt" ftext="albany amt";
10goptions xpixels=700 ypixels=375;
2 Code Block
DATA STEP Data
Explanation :
Conversion of birth date (text) to SAS numeric value and calculation of the analysis date range (today +/- 30 days). Storage of these values in macro variables.
Copied!
1DATA foo;
2bdate="&birthdate"d;
3call symput('bdate',bdate);
4today=today();
5call symput('today',today);
6startdate=today-30;
7enddate=today+30;
8call symput('startdate',startdate);
9call symput('enddate',enddate);
10RUN;
3 Code Block
DATA STEP Data
Explanation :
Generation of biorhythm data. For each day of the period, calculation of sinusoidal values for physical (23 days), emotional (28 days), and intellectual (33 days) cycles.
Copied!
1DATA mydata;
2 LENGTH id $15;
3 FORMAT date date9.;
4 FORMAT value percentn7.0;
5 d2r=(atan(1)/45); /* degrees to radians conversion factor */
6 DO Date = &startdate to &enddate BY 1;
7 t=Date-&bdate; /* days since birth */
8 /* similar to value=sin(2*pi * t/23) ... */
9 Value = sin((t/23)*360*d2r); id='Physical'; OUTPUT;
10 Value = sin((t/28)*360*d2r); id='Emotional'; OUTPUT;
11 Value = sin((t/33)*360*d2r); id='Intellectual'; OUTPUT;
12 END;
13RUN;
4 Code Block
PROC GPLOT
Explanation :
Definition of graphical elements (titles, axes, symbols, legend) and creation of the linear biorhythm chart with PROC GPLOT.
Copied!
1title1 "Biorhythm Chart";
2title2 "For someone born &birthdate";
3 
4axis1 label=none order=(-1 to 1 BY .50) value=(color=gray33 h=3.5) minor=none offset=(0,0);
5axis2 label=none order=(&startdate to &enddate BY 30) value=(color=gray33 h=3.5) minor=(number=29) offset=(0,0);
6 
7symbol1 color=red i=join value=none width=2;
8symbol2 color=blue i=join value=none width=2;
9symbol3 color=cx00ff00 i=join value=none width=2;
10 
11legend1 label=none position=(bottom center) across=3;
12 
13PROC GPLOT DATA=mydata;
14plot Value*Date=id /
15 vref=(-.5 0 .5)
16 cvref=(graydd black graydd)
17 href=(&today)
18 chref=(black)
19 vaxis=axis1
20 haxis=axis2
21 legend=legend1
22 cframe=white
23 ;
24RUN;
25QUIT;
5 Code Block
ODS CLOSE
Explanation :
Closing the ODS HTML destination.
Copied!
1ods html close;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.