It's really difficult to generalize from data with only one ID. Are there always two records for each ID? Are there ever one or three records for each ID? What do we do in those cases? Are the records for ID consecutive and in the proper order?
Please try to give us meaningful examples that cover a number of realistic outcomes, instead of one possible outcome.
Is the end result always the ID followed by the exact unchanging text "screening/day-1"? Or are there other possible text strings that might appear? Give us a realistic example.
@Sowmya12 wrote:
Yes that is the exact output with same id
data want;
set have;
by subjid visit;
if first.visit then text="screening/day-1";
else delete;
run;
You need to transpose it and then concatenate the columns.
data example;
length visit $ 25;
input subjid visit $ ;
datalines;
101 screening
101 day-1
102 screening
102 day-1
103 screening
103 day-1
;
run;
proc sort data=example;
by subjid;
run;
proc transpose data=example out=example_t(drop=_name_);
by subjid;
var visit;
run;
data example_t2;
set example_t;
visit=strip(col1)||'/'||strip(col2);
drop col1 col2;
run;
data have; input subjid visit : $20.; cards; 101 screening 101 day-1 102 screening 102 day-1 103 screening 103 day-1 ; data want; do until(last.subjid); set have; by subjid; length want $ 80; want=catx('/',want,visit); end; drop visit; run;
Can you please post some sample data as datalines? What is the dataset you want? 1 row per subjid?
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.