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-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!

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.

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