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(;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1450 views
  • 1 like
  • 3 in conversation