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

 Hello All,  

 

I think there's a simple solution to this, but nothing I’ve tried is panning out. 

 

The problem: I have repeated measures (test trials) for each individual (i.e., case). They are stacked in a long format(see below).

 

Not every individual has the same number of observations.  They range from 0 to 48, where 0 represents those who failed practice trials and thus didn’t progress onto subsequent trials (e.g., id = 1). 48 represents those who made it to the end of all possible trials (e.g., id = 3). Other individuals were kicked out somewhere between 0 and 48 trials (e.g., Id = 2).

 

I’d like 48 rows for every case, where trials that occur after the case was kicked out are treated as incorrect (i.e., correct = 0).

 

Any thoughts or suggestions would be much appreciated. Thank you in advance.  

 

-dan

 

What I have:

ID

Correct

1

.

2

1

2

1

2

0

2

1

3

1

3

1

3

1

3

1

3

1

3

0

3

3

…48 total rows

 

What I want:

ID

Correct

1

0

1

0

1

…0

1

…48 total rows

2

1

2

1

2

0

2

1

2

…0

2

…48 total rows

3

1

3

1

3

1

3

1

3

0

3

3

…48 total rows

 

 

  

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21
data want (drop=counter);
  set have;
  by id;
  if first.id then counter=1;
  else counter+1;
  output;
  Correct=0;
  if last.id and counter lt 48 then do i=counter+1 to 48;
    output;
  end;
run;

Art, CEO, AnalystFinder.com

View solution in original post

2 REPLIES 2
art297
Opal | Level 21
data want (drop=counter);
  set have;
  by id;
  if first.id then counter=1;
  else counter+1;
  output;
  Correct=0;
  if last.id and counter lt 48 then do i=counter+1 to 48;
    output;
  end;
run;

Art, CEO, AnalystFinder.com

coltraned
Calcite | Level 5
Thanks, Art!

Works perfectly! I can stop banging my head against the wall now!

##- Please type your reply above this line. Simple formatting, no
attachments. -##

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 650 views
  • 0 likes
  • 2 in conversation