Hi,
I have data in this format....
| Header 1 | Header 2 | Header 3 | Header 4 |
|---|---|---|---|
| 1 | AA | RAP12345 | |
| 2 | AA | D | |
| 3 | AA | C | |
4 | AA | RAP34521 | |
| 5 | AA | F | |
| 6 | AA | D |
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 1 | Header 2 | Header 3 | Header 4 |
|---|---|---|---|
| 1 | AA | RAP12345 | RAP12345 |
| 2 | AA | D | RAP12345 |
| 3 | AA | C | RAP12345 |
4 | AA | RAP34521 | RAP34521 |
| 5 | AA | F | RAP34521 |
| 6 | AA | D | RAP34521 |
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;
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;
length header4 $ 8 ; /* or whatever length header3 has before the Retain*/
"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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.