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.
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →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.