DATA Step, Macro, Functions and more

Re: concatenating variable number of text lines with identical keys in table

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

Re: concatenating variable number of text lines with identical keys in table

 
Hello All.  I'm back again.  
 
My code below works, but it cuts off much earlier than the max length I set it for.  

Whenever the date_time stamp is concatenated with it, it appears not to be able to take the full string for seq 1 (line one) of each note.

I came across another post saying that if there is a where clause in the statement then cats and cat() can only handle $200 length.  This is a huge problem for me as I can't have the middle of messages just drop off.

 

Can anyone think of a way where I can:

 

a)  conditionally insert a record for each (ID Time_STAMP) combination that I could then run the following code on where it would not be subject to this constraint?

 

b) concat the timestamp to the begining of the note without using my if seq=1 line (that I think is causing the limit of characters

 

c) redistribute the the text that would be cut off, to the next line, on and on down to the last line

 

d)re-arrange my code in a way that would still make this work and would not be subject to the the text cutting off before 32767 character limit.

 

 

Here's an example of what's happening (and see pic below and excel document attached containing what's in the picture):

 

Survey     ID    date_time       Seq      time_key           Textx

123          1      sasdatetime1   1         sastime1          Hello

123          1      sasdatetime1   2        sastime1           World

123           1     sasdatetime2   1        sastime2           Good

123           1     sasdatetime2   2        sastime2           Bye

....

so what the code below produces is:

123     1         sasdatetime 1        2     sastime1       (sastime1) Hel World

 

 (See actual) case in attached excel document.  Although I've set textx and new_text fields for 

length new_text $32767;

 

.Sample for SasForum.jpg

 

 

 

data notes;
set other.SUPPLY_NOTES;
length Textx $32767;
keep ID Survey SEQ Textx Item_Steps time_key date_time;
If (SEQ=1 and item_steps not in ("","."," ")) 
then do textx=cat('(',put(date_time,datetime18.),') ','||',"ITEM: ",ITEM_Steps,' || ',textx);
end; data notes; set other.SUPPLY_NOTES; keep ID Survey SEQ Textx Item_Steps time_key date_time; where survey="115"; run;
proc sort data=notes; by id time_key SEQ; Run;
proc sort data=itemnotes; by id time_key SEQ; Run;
data notesconcat; set notes; by ID time_key Seq; length new_text $32767; retain new_text; new_text=catx(' ',new_text,textx); if last.id then do; output; call missing(new_text); drop line Textx; end; run;

 

Thank you all for your assistance in advance!

 
 

Accepted Solutions
Solution
‎04-22-2016 05:48 PM
Occasional Contributor
Posts: 15

Re: concatenating variable number of text lines with identical keys in table

I figured it out.  Apparently the source table was imposing a limit on the textx variable of 60 characters.  When I concatenated date_time to the values with seq=1 it would exceed 60char and drop the remaining characters before concatenating the next line.

View solution in original post


All Replies
Super User
Posts: 17,962

Re: concatenating variable number of text lines with identical keys in table

No attachment. 

Can you post data/code that replicates your issue please. You should be able to go up to length 32K/64K without any issues. 

Solution
‎04-22-2016 05:48 PM
Occasional Contributor
Posts: 15

Re: concatenating variable number of text lines with identical keys in table

I figured it out.  Apparently the source table was imposing a limit on the textx variable of 60 characters.  When I concatenated date_time to the values with seq=1 it would exceed 60char and drop the remaining characters before concatenating the next line.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 296 views
  • 0 likes
  • 2 in conversation