BookmarkSubscribeRSS Feed
Rajesh42z
Calcite | Level 5

string can be of any length(dynamic), split it into mulitple variables with a limit 200 for each variables its should be dynamic
example "FAOBJ_1" to "FAOBJ_<n>",
example "AE Term - 1" to "AE Term - <n>"

6 REPLIES 6
ballardw
Super User

Examples without rules can not be programmed to be very flexible. What are the rules for splitting the values.

Provide some examples where the lengths of the source strings are over 200 and what the resulting 200 length values look like after applying the rules.

 

I am not at all sure what your example is even suggesting. I do not see anything split. What I see is "replace 1 with <n>". Split implies that the result is two or more different values into two variables and you only show one result.

Rajesh42z
Calcite | Level 5

q1="Patient's symptoms and behaviors of the psychiatric AE are similar to the ones that patient is normally experiencing. They are not different from the symptoms patient had when he got

admitted to the hospital and which we observed during visits 1and 2. Patient remained hearing voices of imperative and commenting nature in his head, he retained ideas of external influence

on his thoughts and body. As he was receiving the studied drug, anxiety levels have decreased and sleep quality has improved. However, psychosis has remained during visits 9 and 10, for this reason patient needed to remain in the hospital for treatment. According to the Study Protocol, this situation was registered as SAE."

q1 is the string with length of  694   not the same for other records so we need to spllit this string into multiple variables so here we will have to create 4(this also has to be dynamic) variables one String=""/String1=""/String2=""/String3=""

1st first string with 1-199

2nd string 200-399

3rd string 400-599

4th string 600-694

the above is just one sencario we have string with length of 745/480 and so on

Tom
Super User Tom
Super User

Do you want the long string split into multiple VARIABLES?

data want;
  set have;
  array q1_ [5] $200 ;
  do index=1 to length(q1) by 200;
     q1_[index]=substrn(q1,index,200);
  end;
  drop index;
run;

or multiple OBSERVATIONS?

data want;
  set have;
  length rowno 8 newq1 $200;
  do rowno=1 by 1 until(200*(rowno-1)>=length(q1));
    newq1=substrn(q1,1+200*(rowno-1),200);
    output;
  end;
run;

 

Rajesh42z
Calcite | Level 5

q1="Patient's symptoms and behaviors of the psychiatric AE are similar to the ones that patient is normally experiencing. They are not different from the symptoms patient had when he got

admitted to the hospital and which we observed during visits 1and 2. Patient remained hearing voices of imperative and commenting nature in his head, he retained ideas of external influence

on his thoughts and body. As he was receiving the studied drug, anxiety levels have decreased and sleep quality has improved. However, psychosis has remained during visits 9 and 10, for this reason patient needed to remain in the hospital for treatment. According to the Study Protocol, this situation was registered as SAE."

q1 is the string with length of  694   not the same for other records so we need to spllit this string into multiple variables so here we will have to create 4(this also has to be dynamic) variables one String=""/String1=""/String2=""/String3=""

1st first string with 1-199

2nd string 200-399

3rd string 400-599

4th string 600-694

 

the above is just one sencario we have string with length of 745/480 

data_null__
Jade | Level 19
data test;
q1="Patient's symptoms and behaviors of the psychiatric AE are similar to the ones that patient is normally experiencing. They are not different from the symptoms patient had when he got
admitted to the hospital and which we observed during visits 1and 2. Patient remained hearing voices of imperative and commenting nature in his head, he retained ideas of external influence
on his thoughts and body. As he was receiving the studied drug, anxiety levels have decreased and sleep quality has improved. However, psychosis has remained during visits 9 and 10, for this reason patient needed to remain in the hospital for treatment. According to the Study Protocol, this situation was registered as SAE.";
l = klength(q1);
put _all_;
   array _x[4] $200 FAOBJ_1-FAOBJ_4;
   if _n_ eq 1 then addr=addrlong(_x[1]);
   retain addr; drop addr;
   call pokelong(q1,addr,l);
   run;
proc contents varnum;
proc print; run;

Capture.PNGCapture1.PNG

Tom
Super User Tom
Super User

@data_null__ 

Yikes.  Only works if the new variables are contiguous in memory.

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