BookmarkSubscribeRSS Feed
teja5959
Obsidian | Level 7

data set in raw.have
data have;
infile datalines dsd truncover;
input subjid $ THER NEWTR CHTR SHOS OTHER ;
datalines;
101,1,1,1,1,1,.,
102,1,1,1,1,.
103,1,1,1,,
104,1.,1,,,,.
105,1,,.,,.,
106,1,.,1,.,.,.,
107,.,1.,,1,1,.,.
108,.,1.,1,,.
109,.,1,.,1,.
110,.,1,.,.,.
111,1,.,.,.,.,
112,.,.,1,1,.
113,.,.,1,.
114,.,.,.,1,.
;
run;

 

I want this output

data want ;

length subjid $20 acnoth $200;
infile datalines dsd truncover;
input subjid $ acnoth $;
datalines;
101,"NON-DRUG THERAPY, NEW OTC OR RX DRUG ADDED, CHANGE IN CONCOMITANT MEDICATION, HOSPITALIZATION (INCLUDES ER VISITS),OTER"
102,"NON-DRUG THERAPY, NEW OTC OR RX DRUG ADDED, CHANGE IN CONCOMITANT MEDICATION, HOSPITALIZATION (INCLUDES ER VISITS)"
103,"NON-DRUG THERAPY, NEW OTC OR RX DRUG ADDED, CHANGE IN CONCOMITANT MEDICATION"
104,"NON-DRUG THERAPY, NEW OTC OR RX DRUG ADDED"
105,"NON-DRUG THERAPY"
106,"NON-DRUG THERAPY, CHANGE IN CONCOMITANT MEDICATION"
107,"NEW OTC OR RX DRUG ADDED, HOSPITALIZATION (INCLUDES ER VISITS),OTER"
108,"NEW OTC OR RX DRUG ADDED, CHANGE IN CONCOMITANT MEDICATION"
109,"NEW OTC OR RX DRUG ADDED, HOSPITALIZATION (INCLUDES ER VISITS)"
110,"NEW OTC OR RX DRUG ADDED"
111,"NON-DRUG THERAPY"
112,"CHANGE IN CONCOMITANT MEDICATION, HOSPITALIZATION (INCLUDES ER VISITS)"
113,"CHANGE IN CONCOMITANT MEDICATION"
114,"HOSPITALIZATION (INCLUDES ER VISITS)"
;
run;

I want final output

data fin;
merge have want ;
by subjid ;
run;

3 REPLIES 3
andreas_lds
Jade | Level 19

Sorry, but it is not clear what you want concatenated.

PaigeMiller
Diamond | Level 26

Please explain the logic that lets you go from the input data to the output data. Please give a step by step example.

--
Paige Miller
maguiremq
SAS Super FREQ

I'm not going to format each individual value, but I'm assuming this is what you wanted.

 

data want;
	set have;
	length acnoth $200.;
	array v [*] ther -- other;
	do i = 1 to dim(v);
		if not missing(v[i]) then acnoth = catx(', ', acnoth, vname(v[i]));
	end;
run;

In future posts, please provide more information - we can only make assumptions. If you have actual character values associated with variables, please provide those too.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 990 views
  • 0 likes
  • 4 in conversation