Hello
I need suggestions on the following request.
New varname | Calculation |
kcal_day | = sum of kcal |
discsav_tot | = sum of disc_sav |
discsav_kcal | = sum of kcal for all observations where disc_sav=1 |
discswt_tot | = sum of disc_swt |
Discswt_kcal | = sum of kcal for all observations where disc_swt=1 |
The original data set is
| patid | date | kcal | disc_sav | disc_swt |
| 1 | 13-Dec-14 | 124.8 | 0 | . |
| 1 | 13-Dec-14 | 278.64 | 0 | 1 |
| 1 | 13-Dec-14 | 0 | . | . |
| 1 | 13-Dec-14 | 58.5 | 0 | . |
| 1 | 13-Dec-14 | 1413.255 | 1 | 0 |
| 1 | 13-Dec-14 | 293.76 | 0 | . |
| 1 | 13-Dec-14 | 142.59 | 1 | 0 |
| 1 | 13-Dec-14 | 124.8 | 0 | . |
| 1 | 13-Dec-14 | 0 | . | . |
| 2 | 7-Jan-15 | 144 | 1 | 1 |
| 2 | 7-Jan-15 | 62.424 | 1 | . |
| 2 | 30-Mar-15 | 80.6 | 0 | 0 |
| 2 | 30-Mar-15 | 122 | 0 | . |
| 2 | 30-Mar-15 | 298.89 | 1 | . |
| 2 | 30-Mar-15 | 0 | . | . |
| 2 | 31-Mar-15 | 69.16 | 1 | 0 |
| 2 | 31-Mar-15 | 33.756624 | 0 | . |
| 2 | 31-Mar-15 | 51.072 | 1 | 1 |
| 2 | 31-Mar-15 | 62.62 | 1 | . |
| 2 | 31-Mar-15 | 0 | . | . |
| 2 | 31-Mar-15 | 14.025 | 1 | . |
| 2 | 30-Apr-15 | 10.35 | 1 | . |
| 2 | 30-Apr-15 | 85.92 | 1 | . |
| 2 | 30-Apr-15 | 26.555344 | 1 | 0 |
| 2 | 30-Apr-15 | 105.28 | 1 | . |
The final output wants only one raw per patid and date. Thank you for your suggestion.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.