Hello,
I'm trying to create a new "running" variable in my data set but I cant figure out how to do it with a simple code. This is my dataset:
Trial | Interval | Group | Response | New Variable | |
1 | 1 | 1 | 3 | 23 | = 3 + 8 + 12 |
1 | 1 | 2 | 8 | 23 | = 3 + 8 + 12 |
1 | 1 | 3 | 12 | 23 | = 3 + 8 + 12 |
1 | 2 | 1 | 3 | 28 | = 7 + 18 + 3 |
1 | 2 | 2 | 7 | 28 | = 7 + 18 + 3 |
1 | 2 | 3 | 18 | 28 | = 7 + 18 + 3 |
1 | 3 | 1 | 3 | . | . |
1 | 3 | 2 | 17 | . | . |
1 | 3 | 3 | 12 | . | . |
1 | 4 | 1 | 19 | ||
1 | 4 | 2 | 15 | ||
1 | 4 | 3 | 16 | ||
2 | 1 | 1 | 0 | ||
2 | 1 | 2 | 11 | ||
2 | 1 | 3 | 17 | ||
2 | 2 | 1 | 7 | ||
2 | 2 | 2 | 20 | ||
2 | 2 | 3 | 10 | ||
2 | 3 | 1 | 0 |
The "new variable" should be created by adding up the three response values across all 3 group members for each interval but I would like to keep the sum as a variable (as shown).
Any help would be greatly appreciated.
Thank you.
Thank you. Your advice really helped. I managed to create the variable.
Use SQL with group by on trial, interval and group, sum(response). If you want to keep the data on the detail level just keep response as seprate item in the select clause. SQL will automatically remerge back the sum on the detail rows.
Thank you. Your advice really helped. I managed to create the variable.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.