## program loops and renumerative counting

Solved
Regular Contributor
Posts: 159

# program loops and renumerative counting

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;

set uppy;

by spec;

PTX=LAG(PT);

IF  FIRST.spec then do;

PTX=. ;

END;

run;

The results are as shown:

 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

Accepted Solutions
Solution
‎06-04-2015 01:01 PM
Valued Guide
Posts: 863

## Re: program loops and renumerative counting

This might help but I'm not sure what you are trying to accomplish:

set uppy;

by spec pt;

if first.pt then upgraded = pt;

run;

All Replies
Valued Guide
Posts: 863

## Re: program loops and renumerative counting

Can you add some explanation of why it should be -3?  I don't understand what you are trying to do.

Regular Contributor
Posts: 159

## Re: program loops and renumerative counting

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

Solution
‎06-04-2015 01:01 PM
Valued Guide
Posts: 863

## Re: program loops and renumerative counting

This might help but I'm not sure what you are trying to accomplish:

set uppy;

by spec pt;

if first.pt then upgraded = pt;

run;

Super User
Posts: 6,757

## Re: program loops and renumerative counting

It sounds like you need something very straightforward:

set uppy;

by spec;

if first.spec then upgraded = pt;

run;

Is that the result you are looking for?

Mark ... same idea looks like you posted a minute before me!

🔒 This topic is solved and locked.