I have a data set with the following structure:
Employees Year_ID Permanent Salary Average_Salary
-3 6000
-2 6300
-1 6500
A 0 1 6600 ------
1 6600
2 6700
3 6900
-3 3900
-2 4000
-1 4050
B 0 0 4100 ------
1 4100
2 4250
3 4300
and so on.
I have several thousand employees.
I need to compute the average salary of year (-3) and year(-2) when permanent = 1. Then I need to calculate salary of year(0) and year(1) when permanent = 0. The average values need to be on the row when Year_ID = 0.
Thank you so much for any help.
Welcome to the SAS forum.
Is the data posted what you have? If so, that looks like a report, so I assume you're using PROC REPORT or TABULATE.
It would help if you could illustrate your source data, preferably in a data step and what you want as output and what you've tried so far.
Additionally, for the following criteria, it doesn't look like you have any records that meet your condition. Please make sure your sample data aligns with your conditions.
I need to compute the average salary of year (-3) and year(-2) when permanent = 1
@Reeza can't be more right. Will attempt if requirements are clarified.
My request to Reeza and @ChrisHemedinger et al, Can we have a link or some kind of demo for new community members showing them how to frame a question starting from subject line, a brief definition/description of the problem statement with samples and expected results while they register or perhaps a prompt soon as they register? Just my 2 cents. Thank you!
Hi @novinosrin, that info is readily available in here: How to Get Fast Helpful Answers.That article and others like it are available under Getting Started:
There are also help items in the menu under your profile (see below.) Might make sense to link them under Getting Started as well.
Register now for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
I think this is what you are asking for:
data want;
set have end=done;
if done=0 then set have (keep=salary rename=(salary=forward1) firstobs=2);
back3 = lag3(salary);
back2 = lag2(salary);
if permanent=1 then average_salary = (back2 + back3) / 2;
else if permanent=0 then average_salary = (salary + forward1) / 2;
drop forward1 back2 back3;
run;
Thank you so much for your response. I am extremely sorry I made a mistake in explaining the problem. I apologize for that.
Here is the correct explanation.
a) When Permanent = 1 and Year_ID = -3 then Average_Salary = Salary;
When Permanent = 1 and Year_ID = -2 then Average_Salary = [Salary(Year_ID= -3)+Salary(Year_ID= -2)]/2;
When Permanent = 1 and Year_ID = -1 then Average_Salary = Salary;
When Permanent = 1 and Year_ID = -0 then Average_Salary = Salary;
When Permanent = 1 and Year_ID = 1 then Average_Salary = Salary;
When Permanent = 1 and Year_ID = 2 then Average_Salary = Salary;
When Permanent = 1 and Year_ID = 3 then Average_Salary = Salary;
b)
When Permanent = 0 and Year_ID = -3 then Average_Salary = Salary;
When Permanent = 0 and Year_ID = -2 then Average_Salary = Salary;
When Permanent = 0 and Year_ID = -1 then Average_Salary = Salary;
When Permanent = 0 and Year_ID = -0 then Average_Salary = Salary;
When Permanent = 0 and Year_ID = 1 then Average_Salary = [Salary(Year_ID= 0)+Salary(Year_ID= 1)]/2;
When Permanent = 0 and Year_ID = 2 then Average_Salary = Salary;
When Permanent = 0 and Year_ID = 3 then Average_Salary = Salary;
Thank you.
https://stackoverflow.com/help/how-to-ask
Please review the suggestions in the link above on how to post a good question, and how to make a MCV example.
https://stackoverflow.com/help/mcve
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.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.