BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

In my data the following value is present. My code gave the output i need for all obs except this value. With the code the value is split into five variables rather than four. Please help in my code. Thanks

 

value

The OOO re-trained the site staff on re-conoooting current/active suooocts under the updated main OOO at screening. The site staff printed out the updated OOO and included it in the sooject source documents with a note to use the OOO at the subject's next site visit. The site staff created a note-to-file and reported this doooation to the OOO. The site staff will obtain the subject's re-consent during their next visit for the Oooo 00-000 study. The OOO will verify the OOO has been completed at the next OOO. The OOO reminded the site staff to work with the subject at their next Oooo 00-000 visit to obtain the missing consent signature, otherwise the site staff should document/update their note to file in source to reflect in the inability to obtain the signature (update 00JON2000).

 

code

 

data one;

length temp $200;

set data;

n+1;
do i=1 to countw(value,'');
temp=scan(value,i,' ');len=length(temp)+1;output;
end;
run;

 

data two;
set one;
by n;
retain sum;
if first.n then sum=0;
sum+len;
if sum gt 200 then do;group+1;sum=len;end;
run;

 

data three;
length output $ 200;
do until(last.group);
set two;
by n group;
ouput=catx(' ',output,temp);
end;
run;

 

output needed;

value1                        

 

The OOO re-trained the site staff on re-consenting current/active subjects under the updated main OOO at screening. The site staff printed out the updated OOO and included it in the subject source      

 

value2

documents with a note to use the OOO at the subject's next site visit. The site staff created a note-to-file and reported this deviation to the OOO. The site staff will obtain the subject's re-consent

 

value3

during their next visit for the Oooo 00-000 study. The OOO will verify the OOO has been completed at the next OOO. The OOO reminded the site staff to work with the subject at their next Oooo 00-000

 

value4

 

visit to obtain the missing consent signature, otherwise the site staff should document/update their note to file in source to reflect in the inability to obtain the signature (update 00JON2000).

 

 

output getting;

 

 

value1

The OOO re-trained the site staff on re-consenting current/active subjects under the updated main OOO at screening. The site staff printed out the updated OOO and included it in the subject source

 

value2

documents with a note to use the OOO at the subject's next site visit. The site staff created a note-to-file and reported this deviation to the OOO. The site staff will obtain the subject's

 

value3

re-consent during their next visit for the Oooo 00-000 study. The OOO will verify the OOO has been completed at the next OOO. The CRA reminded the site staff to work with the subject at their next

 

value4

Oooo 00-000 visit to obtain the missing consent signature, otherwise the site staff should document/update their note to file in source to reflect in the inability to obtain the signature (update

 

 value5

21JUN2016).

 

                                    

 

1 REPLY 1
rivieralad
Obsidian | Level 7

Hi

 

I can see what the issue is in your code and the answer is quite simple.

 

You are splitting the text into new variables with a length of 200 characters.

 

When you breakdown the text into single words you add 1 to the length of each word to allow for the space between that word and the next, which is absolutely correct.

However, when you group the words in dataset two, the second data step, you check if the total length of the group is more than 200 but this should be more than 201 as you need to allow for the space on the end of the last word!

If you change the line:

if sum gt 200 then do;group+1;sum=len;end;

to:

if sum gt 201 then do;group+1;sum=len;end;

you will get the results you desire (as long as you correct the mistyped ouput= to output= in the third data step!).

 

Cheers

 

Chris

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 1 reply
  • 739 views
  • 1 like
  • 2 in conversation