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: 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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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