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
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.
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.