Hello all-
I have the following code below-
data uppy;
input spec $1. @3 pt 1.;
datalines;
a 0
a 0
a 0
a 1
a 1
a 1
;
run;
data upgraded_out;
set uppy;
by spec;
PTX=LAG(PT);
IF FIRST.spec then do;
PTX=. ;
END;
UPGRADED=sum(PT,PTX);
run;
The results are as shown:
Obs | spec | pt | PTX | UPGRADED |
1 | a | 0 | . | 0 | |
2 | a | 0 | 0 | 0 | |
3 | a | 0 | 0 | 0 | |
4 | a | 1 | 0 | 1 | |
5 | a | 1 | 1 | 2 | |
6 | a | 1 | 1 | 2 |
The problem is observation 6-I would like the end result to be the total points -3;
I cannot simply sum the values in a proc sql statement as in the end I actually need to output where the upgrade value is only two.
Any assistance greatly appreciated.
Lawrence
This might help but I'm not sure what you are trying to accomplish:
data upgrade;
set uppy;
retain upgraded;
by spec pt;
if first.pt then upgraded = pt;
if not first.pt then upgraded = upgraded+pt;
run;
Can you add some explanation of why it should be -3? I don't understand what you are trying to do.
Thanks Mark & Astounding! That works.
Mark-The final observation should have been 3 and not -3. That was a typo.
In short I will explain-
What the zeros and ones represent are a patient's assessment in an ICU-
0 is not mobile, 1 is mobile. I have a physician who wants data on when a patient is mobile on the second assessment.
And I chose Mark's answer as correct as it was the first one posted (that worked) but they both do the job!
Lawrence
This might help but I'm not sure what you are trying to accomplish:
data upgrade;
set uppy;
retain upgraded;
by spec pt;
if first.pt then upgraded = pt;
if not first.pt then upgraded = upgraded+pt;
run;
It sounds like you need something very straightforward:
data upgraded_out;
set uppy;
by spec;
if first.spec then upgraded = pt;
else upgraded + pt;
run;
Is that the result you are looking for?
Mark ... same idea looks like you posted a minute before me!
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.
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.