BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
CHL0320
Obsidian | Level 7

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 

patiddatekcaldisc_savdisc_swt
113-Dec-14124.80.
113-Dec-14278.6401
113-Dec-140..
113-Dec-1458.50.
113-Dec-141413.25510
113-Dec-14293.760.
113-Dec-14142.5910
113-Dec-14124.80.
113-Dec-140..
27-Jan-1514411
27-Jan-1562.4241.
230-Mar-1580.600
230-Mar-151220.
230-Mar-15298.891.
230-Mar-150..
231-Mar-1569.1610
231-Mar-1533.7566240.
231-Mar-1551.07211
231-Mar-1562.621.
231-Mar-150..
231-Mar-1514.0251.
230-Apr-1510.351.
230-Apr-1585.921.
230-Apr-1526.55534410
230-Apr-15105.281.

 

The final output wants only one raw per patid and date.  Thank you for your suggestion.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
PROC MEANS + CLASS statement or PROC SQL. In general, PROC MEANS is more dynamic, while PROC SQL ends up being hard coded for your situation.

View solution in original post

1 REPLY 1
Reeza
Super User
PROC MEANS + CLASS statement or PROC SQL. In general, PROC MEANS is more dynamic, while PROC SQL ends up being hard coded for your situation.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 988 views
  • 0 likes
  • 2 in conversation