BookmarkSubscribeRSS Feed
Sowmya12
Fluorite | Level 6
If visit contains screening and day1 as
subjid visit
1 101 screening
2 101 day 1
Those visits are present as 2 observations
I need the output as
Subjid visit
101 screening/day-1
10 REPLIES 10
PaigeMiller
Diamond | Level 26

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? 

--
Paige Miller
Sowmya12
Fluorite | Level 6
There are 2 records for every id

101 screening
101 day-1
102 screening
102 day-1
103 screening
103 day-1

Can we get this kind of output as below

101 screening/day-1
102 screening/day-1
103 screening/day-1
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Sowmya12
Fluorite | Level 6
Yes that is the exact output with same id
tarheel13
Rhodochrosite | Level 12
I gave you a solution that gets your desired output.
Sowmya12
Fluorite | Level 6
Thanku for the solution and sorry for problem regarding the question.

Thanks
Sowmya
PaigeMiller
Diamond | Level 26

@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;  
--
Paige Miller
tarheel13
Rhodochrosite | Level 12

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;
Ksharp
Super User
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;
tarheel13
Rhodochrosite | Level 12

Can you please post some sample data as datalines? What is the dataset you want? 1 row per subjid?

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 10 replies
  • 1614 views
  • 1 like
  • 4 in conversation