Hello,I
I have a data sample that looks loke this:
Month Name Income
January Mary 1543
February Mary 1654
March Mary 1578
January Joan 2345
February Joan 2378
March Joan 2350
January Hillary 3567
February Hillary 3678
March Hillary 3456
I want to see the trend for "Income" for each person considering the data from each month. In Excel I could do a graph for each one and use the option "Add trendline". This is just an example, but I have a larer database for which I need to do it. Is there any possibility to do it using SAS? I do not necessarily need a graphic, a result like "ascending" or "descending" would be enough.
Thank you in advance.
Try the following code. It's more complicated than usual because your variable, MONTH, is a character variable
that may not be compatible with a variable specified in the PLOT statement of PROC GPLOT.
Another alternative would be a linear regression using PROC REG, regressing income on month, and looking for
positive, neutral, or negative regression coefficients for month.
=====================================================================================
* Formats for month variables;
proc format;
value $monthfm "January"="1" "Februrary"="2" . . . "December"="12";
value month 1="January" 2="February" . . . 12="December";
run;
* Convert month-names to numbers from 1 to 12;
data new;
set;
monthnum=input(put(month,$monthfm.),8.0);
output new;
run;
* Sort data by name and number of month;
proc sort data=new equals;
by name monthnum;
run;
* Plot income vs. month and interpolate a linear regression line;
* for each name;
symbol1 v=plus i=rl;
proc gplot data=new;
by name;
plot income*monthnum;
format monthnum month.;
run;
quit;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.