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 |
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
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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.