How do you create line plots in SAS? 2

How do you create line plots in SAS?

Line plots are a type of graphical representation that displays the relationship between two continuous variables. In SAS, line plots can be created by using the PROC SGPLOT procedure, which allows for the customization of the plot’s appearance, including the use of different symbols, colors, and line styles. The data used for the line plot can be organized in a vertical or horizontal format, and the plot can be further enhanced by adding titles, labels, and legends. The resulting line plot can provide a visual representation of trends, patterns, and outliers in the data, making it a useful tool for data analysis and interpretation.

Create Line Plots in SAS (With Examples)


You can use proc sgplot to create line plots in SAS.

This procedure uses the following basic syntax:

/*create dataset*/
proc sgplotdata=my_data;
    seriesx=x_variable y=y_variable;run;

The following examples show how to use this procedure to create line plots in SAS.

Example 1: Create Line Plot with One Line

Suppose we have the following dataset in SAS that shows the total sales made by a store during 10 consecutive days:

/*create dataset*/
data my_data;
    input day $ sales;
    datalines;
1 7
2 12
3 15
4 14
5 13
6 11
7 10
8 16
9 18
10 24
;
run;

/*view dataset*/
proc printdata=my_data;

We can use proc sgplot to create a line plot that displays the day on the x-axis and sales on the y-axis:

/*create line plot that displays sales by day*/
proc sgplotdata=my_data;
    series x=day y=sales;
run;

We can use the following code to modify the appearance of the chart, including the title, labels, colors, line pattern, and line thickness:

/*create custom line plot*/
title "Sales by Day";
proc sgplotdata=my_data;
    seriesx=day y=sales / lineattrs=(color=red pattern=dash thickness=4);
    xaxisdisplay=(nolabel noline noticks);
run;
title; 

Example 2: Create Line Plot with Multiple Lines

Suppose we have the following dataset in SAS that shows the total sales made by three different stores during five consecutive days:

/*create dataset*/
data my_data;
    input store $ day $ sales;
    datalines;
A 1 13
A 2 18
A 3 20
A 4 25
A 5 26
B 1 3
B 2 7
B 3 12
B 4 12
B 5 11
C 1 6
C 2 12
C 3 19
C 4 20
C 5 21
;
run;

/*view dataset*/
proc printdata=my_data;

We can use proc sgplot with the group argument to create a line plot that displays the sales made by each of the three stores:

/*create line plot that displays sales by day for each store*/
title "Sales by Day by Store";
proc sgplotdata=my_data;
    styleattrsdatacontrastcolors=(red green blue);
    seriesx=day y=sales / group=store;
run;
title;

The x-axis displays the day and the y-axis displays the sales made by the stores.

The three individual lines show the sales made by each of the three stores during each day.

Additional Resources

Cite this article

stats writer (2024). How do you create line plots in SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-do-you-create-line-plots-in-sas/

stats writer. "How do you create line plots in SAS?." PSYCHOLOGICAL SCALES, 1 Jul. 2024, https://scales.arabpsychology.com/stats/how-do-you-create-line-plots-in-sas/.

stats writer. "How do you create line plots in SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-do-you-create-line-plots-in-sas/.

stats writer (2024) 'How do you create line plots in SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-do-you-create-line-plots-in-sas/.

[1] stats writer, "How do you create line plots in SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, July, 2024.

stats writer. How do you create line plots in SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top