BookmarkSubscribeRSS Feed
thanikondharish
Fluorite | Level 6


data s ;
input studyid $ status $12. seq ;
cards;
1001 screened 1
1001 randomized 2
1001 randomized 2
1002 screened 1
1002 complete 3
1003 screened 1
1003 non-complete 3
1003 non-complete 3
1004 screened 1
1004 screened 1
1005 screefailure 1
1005 screefailure 1
;

 

studyid

status

seq

work

1001

randomized

2

randomized

1001

randomized

2

randomized

1001

screened

1

randomized

1002

complete

3

complete

1002

screened

1

complete

1003

non-complete

3

non-comple

1003

non-complete

3

non-comple

1003

screened

1

non-comple

1004

screened

1

screened

1004

screened

1

screened

1005

screefailure

1

screefailu

1005

screefailure

1

screefailu

 

how to do convert s datasset like above

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Please be more specific about the logic here.

 

How is the work variable determined?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Assign a specific order to the visits, so that they are in the sequence you need, then sort by that, and retain the first one, e.g.

data inter;
  set s;
  select (status);
    when ("screened") then 3;
    when ("randomised") then 1;
    when ("non-complete") then 2;
    otherwise;
  end;
run;

proc sort data=inter;
  by studyid status;
run;
 
data inter;
  set inter;
  by studyid;
  if first.studyid;
run;

data want;
  merge s inter;
  by studyid;
run;

I assume we wont hear back on this topic, or see any of your posts responded to or marked correct?

mkeintz
PROC Star

It appears that you want to apply the last value of work for each id to all the preceding records for the same id.  If so:

 

data want;
  set have;
  by id;
  if last.id then do until (last.id);
    set have (drop=work);
    by id;
    output;
  end;
run;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1107 views
  • 0 likes
  • 5 in conversation