BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

in my raw data, a variable value contains characters longer than 200 characters in length. I need split the value into variable1, variable2, and so on depends on the number of charracters and each variable can contain maximum of 200 characters. Thank you.

 

data

 

Variable

Site to document the deviation in the subject source. Sleep technician will receive addition protocol training for scoring requirements and procedures. Site reported the deviation to the investigator on 20JUN2013.Subject 32 Screening Mean sleep latency could not be determined for this subject as sleep latency was unknown for all of the MWT naps.

3 REPLIES 3
Astounding
PROC Star

Here's a recently asked question that only splits into 2 variables instead of 3 ... but all the same techniques would apply.

 

https://communities.sas.com/t5/General-SAS-Programming/Split-variable-gt-200-char-into-fragments-lt-...

 

Shmuel
Garnet | Level 18

You may try:

length var1-var5 $200;   /* assume max 5 variables to output */

array varx var1-var5;

 

var_len = length(var_in);

do i=1 to 5; varx(i)=' '; end;

 

if var_len le 200 then var1 = var_in;  

else do ;

        i=1;

        do until (var_len < 200);

             varx(i) = substr(var_in,(i-1)*200 +1, min(var_len, 200));

             var_len = var_len - 200;

             i+1;

       end;

 

       

Shmuel
Garnet | Level 18
oops, change the do until (var_len < 200); into
DO WHILE (VAR_LEN > 0(;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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