BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rkolupoti9001
Calcite | Level 5

Hi,

I have data in this format....

Header 1Header 2Header 3Header 4
1AARAP12345
2AAD
3AAC

4

AARAP34521
5AAF
6AAD

How to create this to this format.(there are more than 300 occurances in a single file or these with more than 1 million rows.)

The header 4 should be filled with data when ever it starts with RAP...

Header 1Header 2Header 3Header 4
1AARAP12345RAP12345
2AADRAP12345
3AACRAP12345

4

AARAP34521RAP34521
5AAFRAP34521
6AADRAP34521
1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

data have;

input Header1 Header2 $ Header3 $;

datalines;

1 AA RAP12345

2 AA D

3 AA C

4 AA RAP34521

5 AA F

6 AA D

;

data want;

set have;

retain Header4;

if find(Header3,'RAP') then Header4=Header3;

run;

View solution in original post

3 REPLIES 3
stat_sas
Ammonite | Level 13

data have;

input Header1 Header2 $ Header3 $;

datalines;

1 AA RAP12345

2 AA D

3 AA C

4 AA RAP34521

5 AA F

6 AA D

;

data want;

set have;

retain Header4;

if find(Header3,'RAP') then Header4=Header3;

run;

ballardw
Super User

length header4 $ 8 ; /* or whatever length header3 has before the Retain*/

Haikuo
Onyx | Level 15

"when ever it starts with RAP" makes me thinking, instead of " if find(Header3,'RAP') then Header4=Header3; ", using:

if header3 =:'RAP'  then Header4=Header3;

Regards,

Haikuo

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1074 views
  • 3 likes
  • 4 in conversation