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

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:

ObsspecptPTXUPGRADED
                            a   0 .     0
                            a   0 0     0
                            a   0 0     0
                            a   1 0     1
                            a   1 1     2
                            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

1 ACCEPTED SOLUTION

Accepted Solutions
Steelers_In_DC
Barite | Level 11

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;

View solution in original post

4 REPLIES 4
Steelers_In_DC
Barite | Level 11

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

LB
Quartz | Level 8 LB
Quartz | Level 8

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

Steelers_In_DC
Barite | Level 11

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;

Astounding
PROC Star

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!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 4 replies
  • 1581 views
  • 3 likes
  • 3 in conversation