Data editing in SAS

My data looks like this:

VAR1
TITLE A
APPLICATION #1
APPLICATION #2
APPLICATION #3
TITLE B
APPLICATION #4
APPLICATION #5
APPLICATION #6
TITLE C
APPLICATION #4
APPLICATION #5
APPLICATION #6

I’d like the result to look like VAR2 below

VAR1 VAR2
TITLE A TITLE A
APPLICATION #1 TITLE A
APPLICATION #2 TITLE A
APPLICATION #3 TITLE A
TITLE B TITLE B
APPLICATION #4 TITLE B
APPLICATION #5 TITLE B
APPLICATION #6 TITLE B
TITLE C TITLE C
APPLICATION #4 TITLE C
APPLICATION #5 TITLE C
APPLICATION #6 TITLE C

To be more exact, I’d like it to be like this, but if I get above, I can get this myself:

VAR1 VAR2
APPLICATION #1 TITLE A
APPLICATION #2 TITLE A
APPLICATION #3 TITLE A
APPLICATION #4 TITLE B
APPLICATION #5 TITLE B
APPLICATION #6 TITLE B
APPLICATION #4 TITLE C
APPLICATION #5 TITLE C
APPLICATION #6 TITLE C

Thanks Charly:

*****;
data a;
input VAR1 &$30.;
cards;
TITLE A
APPLICATION #1
APPLICATION #2
APPLICATION #3
TITLE B
APPLICATION #4
APPLICATION #5
APPLICATION #6
TITLE C
APPLICATION #4
APPLICATION #5
APPLICATION #6
;

data b;
set a;
if var1 =: 'TITLE' then var2=var1;
else output;
retain var2;
run;

proc print ; run;

Leave a Reply