Published on :
Statistical INTERNAL_CREATION

PROC LOESS Introduction Example: Melanoma Incidences

This code is also available in: Deutsch Español Français
Awaiting validation
This script creates a 'Melanoma' dataset containing annual records. It begins by visualizing raw data with PROC SGPLOT. Then, it progressively uses PROC LOESS: first with default parameters, then by requesting statistical details, comparing different smoothing parameters (smooth option), exporting results via ODS OUTPUT, and finally displaying confidence intervals (CLM).
Data Analysis

Type : INTERNAL_CREATION


Data is included directly in the script via the DATALINES statement (Melanoma dataset).

1 Code Block
DATA STEP Data
Explanation :
Creation of the 'Melanoma' dataset. The INPUT statement is configured to read multiple 'Year Incidence' pairs per line (note: the source code contains a file reference artifact where the '@@' symbol is expected for continuous reading).
Copied!
1DATA Melanoma;
2 INPUT Year Incidences @@;
3 FORMAT Year d4.0;
4 DATALINES;
51936 0.9 1937 0.8 1938 0.8 1939 1.3
61940 1.4 1941 1.2 1942 1.7 1943 1.8
71944 1.6 1945 1.5 1946 1.5 1947 2.0
81948 2.5 1949 2.7 1950 2.9 1951 2.5
91952 3.1 1953 2.4 1954 2.2 1955 2.9
101956 2.5 1957 2.6 1958 3.2 1959 3.8
111960 4.2 1961 3.9 1962 3.7 1963 3.3
121964 3.7 1965 3.9 1966 4.1 1967 3.8
131968 4.7 1969 4.4 1970 4.8 1971 4.8
141972 4.8
15;
2 Code Block
PROC SGPLOT
Explanation :
Generation of a scatter plot to visualize the evolution of incidences over time before modeling.
Copied!
1 
2PROC SGPLOT
3DATA=Melanoma;
4scatter y=Incidences x=Year;
5RUN;
6 
3 Code Block
PROC LOESS
Explanation :
Activation of ODS graphics. First execution of PROC LOESS with default options to fit a local regression curve.
Copied!
1ods graphics on;
2 
3PROC LOESS DATA=Melanoma;
4 model Incidences=Year;
5RUN;
4 Code Block
PROC LOESS
Explanation :
Execution of PROC LOESS requesting additional details in the output: model summary and output statistics.
Copied!
1 
2PROC LOESS
3DATA=Melanoma;
4model Incidences=Year / details(ModelSummary OutputStatistics);
5RUN;
6 
5 Code Block
PROC LOESS Data
Explanation :
Modeling with explicit specification of several smoothing parameters for comparison. The 'residual' option requests residual calculation. Output statistics are saved to the SAS table 'Results' via ODS OUTPUT.
Copied!
1PROC LOESS DATA=Melanoma;
2 model Incidences=Year/smooth=0.1 0.25 0.4 0.6 residual;
3 ods OUTPUT OutputStatistics=Results;
4RUN;
6 Code Block
PROC PRINT
Explanation :
Display of the first 5 observations from the previously created 'Results' table.
Copied!
1PROC PRINT DATA=Results(obs=5);
2 id obs;
3RUN;
7 Code Block
PROC LOESS
Explanation :
Execution aimed at producing a specific plot of residuals by smoothing parameter (ResidualsBySmooth).
Copied!
1 
2PROC LOESS
3DATA=Melanoma plots=ResidualsBySmooth(smooth);
4model Incidences=Year/smooth=0.1 0.25 0.4 0.6;
5RUN;
6 
8 Code Block
PROC LOESS
Explanation :
Final model requesting confidence limits (CLM) with an alpha threshold of 0.1 (90% confidence interval). ODS graphics are turned off at the end.
Copied!
1PROC LOESS DATA=Melanoma;
2 model Incidences=Year/clm alpha=0.1;
3RUN;
4 
5ods graphics off;
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.
Copyright Info : SAS SAMPLE LIBRARY


Banner
Expert Advice
Expert
Stéphanie
Spécialiste Machine Learning et IA.
« When dealing with time-series data like melanoma incidences, a simple linear regression often fails to capture localized fluctuations. PROC LOESS (LOcal regrESSion) provides a non-parametric alternative, creating a smooth curve that "follows" the data points without forcing them into a rigid global mathematical shape (like a straight line or parabola). »