Hi there, something like this solve your problem?
data have;
input id wait_time pts_1 pts_2 pts_3;
datalines;
1 12.85 1.67 2 1.5
;
run;
data want;
set have;
array pts pts:;
do over pts;
pts=pts+wait_time;
end;
run;
-unison
@unison wrote:
Hi there, something like this solve your problem?
data have; input id wait_time pts_1 pts_2 pts_3; datalines; 1 12.85 1.67 2 1.5 ; run; data want; set have; array pts pts:; do over pts; pts+wait_time; end; run;
-unison
The statement
pts+wait_time;
will work for this problem, as stated. But I would NOT recommend it. This is a SAS SUMming statement, which means (1) is will accumulated values over consecutive observations (not a problem here), and (2) will not always produce the same results as
pts=pts+wait_time;
Take a look at the results for observations 3 and 4 below, where there are missing values introduced:
data have;
input id wait_time pts_1 pts_2 pts_3;
datalines;
1 12.85 1.67 2 1.5
2 11.85 1.67 2 1.5
3 10.85 . 2 1.5
4 . 1.67 2 1.5
run;
data want1;
set have;
array pts pts:;
do over pts;
pts+wait_time;
end;
run;
data want2;
set have;
array pts pts:;
do over pts;
pts=pts+wait_time;
end;
run;
Arrays are the recommend approach here.
Here's a tutorial on using Arrays in SAS
https://stats.idre.ucla.edu/sas/seminars/sas-arrays/
@Gator77 wrote:
Hello,
I’m working on a rather large data set that I need to add one value to several hundred other values in the same row.
And example would be:
ID Wait Time Pts 1 Pts 2 Pts 3 etc.
1 12.85 1.67 2 1.5.
Output
14.52 14.85 14.35
There has to be an easier way to do this without manually inputting formulas one by one for each value.
Thanks
@Gator77 wrote:
Hello,
I’m working on a rather large data set that I need to add one value to several hundred other values in the same row.
And example would be:
ID Wait Time Pts 1 Pts 2 Pts 3 etc.
1 12.85 1.67 2 1.5.
Output
14.52 14.85 14.35
There has to be an easier way to do this without manually inputting formulas one by one for each value.
Thanks
I think that you need to walk us through the explicit formula you are using. The input data has 5 values and the output only 3. So which variables are used and how to get that output??
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!
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.