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

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
  • 470 views
  • 3 likes
  • 4 in conversation