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

Hi,

I am trying to sum across variables, but only if a separate variable is greater than a certain value. Here's an example:

IDday1day2day3dollar1dollar2dollar3magicday
1010121234
20151232

For any of the days (day1-day3) that are greater than the magicday, I want to sum their corresponding dollar values. For example, for person 1, since their magicday is 4, I want to add the dollar

values from day2 and day3 and get a total sum of $5, and ignore the dollars from day 1. For person 2, I want only the dollar value from day3, $3.

I actually have over 400 days to deal with, so doing this manually isn't really an option.

Thanks so much!

Laurie

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use a do loop and arrays.

data want;

set have;

array day(100) day1-day100;

array dollar(100) dolalr1-dollar100;

dollar_total=0;

do i=1 to 100;

     if day(i)>magicday then dollar_total+dollar(i);

end;

run;

View solution in original post

2 REPLIES 2
Reeza
Super User

Use a do loop and arrays.

data want;

set have;

array day(100) day1-day100;

array dollar(100) dolalr1-dollar100;

dollar_total=0;

do i=1 to 100;

     if day(i)>magicday then dollar_total+dollar(i);

end;

run;

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 679 views
  • 0 likes
  • 2 in conversation