From: Katy Seib on
**Intro
First, thanks To Ron for posting the SAS-L wiki this morning- very helpful!
I too am relatively new to posting at the listserv but have enjoyed reading
for a while. I'm a guest researcher at CDC and a grad student finishing up
my thesis which is a longitudinal study - much of which is beyond the scope
of my formal SAS education - I've had fun finding resources like this, UCLA
and various SAS tips across the internet. I think my question today is
relatively simple but a problem for me nonetheless.
**Problem
I have been calculating variables and have a LONG but effective algorithm
for "filling in" variables that are constant across an observation. It's
tedious and I still worry about errors. I know there must be a simpler way
to fill in this information AS it's calculated. Below I have included an
example and sample data. The SAM variable is a crude time variable and in
reality there are 23 serotypes. The data step "correlate" gives me the
yes/no answer for sam=3 only but I need it for all sam (the question being
answered by calculating this variable is: "did this infant have a antibody
titer greater than .35 at 10 weeks (sam=3)?". Here I've done it for
Serotype_1 but will have to do it for all serotypes. I'm not pasting my fill
in code because it's long and clumsy requiring 6 data steps. This is not a
first occurrence var, so I'm having trouble applying previous similar
solutions. Thanks all.

data ALLFILLED;
input ID SAM SEROTYPE_1 SEROTYPE_9V;
cards;
1 0.2 8.22 36.1
1 0.3 1.81 22.1
1 1.0 .41 4.8
1 2.0 .33 3.2
1 3.0 .30 2.1
1 4.0 .23 2.0
1 5.0 .10 1.9
1 6.0 .03 0.9
2 0.2 38.1 100.3
2 0.3 25.81 95.2
2 1.0 22.3 66.2
2 2.0 21.5 54.2
2 3.0 18.3 49.5
2 4.0 6.2 31.1
2 5.0 6.1 23.3
2 6.0 3.1 22
;
RUN;

PROC PRINT DATA=ALLFILLED; RUN;

DATA CORRELATE;
SET ALLFILLED;
IF SAM=3 AND SEROTYPE_1=. THEN CORR3_SER1=.;
ELSE IF SAM=3 AND SEROTYPE_1>.35 THEN CORR3_SER1=1;
ELSE IF SAM=3 AND SEROTYPE_1<.35 THEN CORR3_SER1=0;
BY ID;
RUN;

PROC PRINT DATA=CORRELATE; RUN;