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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.