BookmarkSubscribeRSS Feed
thanikondharish
Calcite | Level 5


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

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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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