BookmarkSubscribeRSS Feed
Soham0707
Obsidian | Level 7

Hello guys, 

 

I have below data set in which i want the values of reason in one record by subject & Visit description.

 
 
 
Subject Visit_description Start_date End_date Reason Other_Reason
1 Assessment 1 6/26/2020 6/26/2020 CONVULSIONS  
1 Assessment 1 6/26/2020 6/26/2020 DEHYDRATION  
1 Assessment 1 6/26/2020 6/26/2020 FEEDING DIFFICULTY  
1 Assessment 1 6/26/2020 6/26/2020 OTHER iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
1 Assessment 2 6/27/2020 6/27/2020 IRREGULAR OR PERIODIC RESPIRATION  
1 Assessment 2 6/27/2020 6/27/2020 IRRITABILITY OR AGITATION  

1

 

Assessment 2 6/27/2020 6/27/2020 LETHARGY OR EXCESSIVE SLEEPINESS  

 

Output should be like below table

Subject  Visit_description Start_date End_date Reason Other_Reason
1 Assessment 1 6/26/2020 6/26/2020 CONVULSIONS,DEHYDRATION,FEEDING DIFFICULTY,OTHER iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
1 Assessment 2 6/27/2020 6/27/2020 IRREGULAR OR PERIODIC RESPIRATION,IRRITABILITY OR AGITATION,LETHARGY OR EXCESSIVE SLEEPINESS  

 

7 REPLIES 7
Shmuel
Garnet | Level 18

Try next code:

data want;
 set have(rename=(reason = _reason));
  by Sunject Visit_desription;
     retain reason;
	 length reason $100; /* adapt to max neaded */
	 
	 if first.Visit_desription then reason = ' ';
	 reason = catx(',',reason,_reason);
	 if last.Visit_desription then output;
run;
Soham0707
Obsidian | Level 7
not working 😞
Kurt_Bremser
Super User

@Soham0707 wrote:
not working 😞

Very bad answer, totally unhelpful.

Please describe in detail what "did not work".

Did you get ERRORs or WARNINGs? Or did the code run, but not produce the expected output?

In all cases, post the log, using the </> button. Point out the difference between expected and actual result.

Soham0707
Obsidian | Level 7
Sorry for that..
This warning i got and output is not matching..

WARNING: In a call to the CATX function, the buffer allocated for the result was not long enough to contain the concatenation of all the arguments. The correct result would contain 5
characters, but the actual result might either be truncated to 1 character(s) or be completely blank, depending on the calling environment. The following note indicates the
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

left-most argument that caused truncation.
NOTE: Argument 3 to function CATX(',',' '[12 of 50 characters shown],'OTHER '[12 of 160 characters shown]) at line 30431 column 14 is invalid.
Kurt_Bremser
Super User

By "post the log" I meant to post the whole log of your step, including the complete code of the step and all follow-up messages. And, as requested, you must (MUST) use the </> button to keep the formatting of the log. This is important, as the horizontal position of ERROR markers helps in identifying the cause of an ERROR, and this positioning is destroyed by the main posting window.

Shmuel
Garnet | Level 18

@Soham0707 wrote:
Sorry for that..
This warning i got and output is not matching..

WARNING: In a call to the CATX function, the buffer allocated for the result was not long enough to contain the concatenation of all the arguments. The correct result would contain 5
characters, but the actual result might either be truncated to 1 character(s) or be completely blank, depending on the calling environment. The following note indicates the
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

left-most argument that caused truncation.
NOTE: Argument 3 to function CATX(',',' '[12 of 50 characters shown],'OTHER '[12 of 160 characters shown]) at line 30431 column 14 is invalid.

If you check the posted code it written explicitley:

length reason $100; /* adapt to max needed */

I cannot know what is the maximum number of reasons will be concatenated.

You can change the length to 1000 up to 32000 but better evaluate it or just increase until there will be no more such warnings.

 

Do you need or prefer sorting the concatenated reasons or leave them in order as they arrived? Can there be a reason more then once per subject?

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
  • 7 replies
  • 904 views
  • 1 like
  • 3 in conversation