BookmarkSubscribeRSS Feed
sasuser143
Calcite | Level 5

If there are number of observations in the same variable, how to separate them

 

data have ;

101 1-LIGHT SENSITIVITY OU_2-BURNING OU_3-PUNCTATE EPITHELIAL EROSION OU

102 1-Cellulitis of right lower extremity_2-Abscess of the right lower extremity

103 1-Burning (Forehead, Left Cheek, Right Cheek, Chin)_2-Itching (Forehead, Left Cheek, Right Cheek, Chin)_3-Stinging (Forehead, Left Cheek, Right Cheek, Chin)

104 1-LIGHT SENSITIVITY OU

run;

 

 

data want ;

101    LIGHT SENSITIVITY OU

101    BURNING OU

101    PUNCTATE EPITHELIAL EROSION OU

102    Cellulitis of right lower extremity

102     Abscess of the right lower extremity

103     Burning (Forehead, Left Cheek, Right Cheek, Chin)

103     Itching (Forehead, Left Cheek, Right Cheek, Chin)

103     Stinging (Forehead, Left Cheek, Right Cheek, Chin)

104     LIGHT SENSITIVITY OU

run;

 

2 REPLIES 2
Kurt_Bremser
Super User

The SCAN function accepts a third parameter which defines the delimiter. Use it in a DO loop with the underline as delimiter, and a second time with the hyphen as delimiter to remove the leading digit.

PeterClemmensen
Tourmaline | Level 20

If you data is representable, then try

 

data have;
input ID string $ 4 - 200;
datalines;
101 1-LIGHT SENSITIVITY OU_2-BURNING OU_3-PUNCTATE EPITHELIAL EROSION OU                                                                                         
102 1-Cellulitis of right lower extremity_2-Abscess of the right lower extremity                                                                                 
103 1-Burning (Forehead, Left Cheek, Right Cheek, Chin)_2-Itching (Forehead, Left Cheek, Right Cheek, Chin)_3-Stinging (Forehead, Left Cheek, Right Cheek, Chin) 
104 1-LIGHT SENSITIVITY OU                                                                                                                                       
;

data want(keep = id w);
   set have;
   by ID;
   length w $200;
   c = countw(string,, 'd');
   do i = 1 to c;
      w = compress(scan(string, i,, 'd'), '_-');
      output;
   end;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 519 views
  • 1 like
  • 3 in conversation