sas >> Recode Variables

by cbook76 » Wed, 04 Nov 2009 20:51:40 GMT

Hi,

I have a data set which is in long form. I have some variables (i.e. gender,
ethnicity) where the data is missing for specific waves, although I know the
values at baseline. I would like to copy the baseline value onto the rest of
the waves. Here is an example:

ID Wave Eth Sex
1 1 1 2
1 2 . .
1 3 . .
1 5 . .
2 1 2 1
2 2 . .
2 5 . .
2 7 . .

I would like it to look like:
ID Wave Eth Sex
1 1 1 2
1 2 1 2
1 3 1 2
1 5 1 2
2 1 2 1
2 2 2 1
2 5 2 1
2 7 2 1

Thank you,

Cara

sas >> Recode Variables

by kirhizau » Wed, 04 Nov 2009 21:08:53 GMT


Hi Cara,
You might want to try retain statement
Here is just an idea.

Data want;
Set have;
Retain _eth ;
If eth ne . then _eth = eth;
Eth = _eth;
Run;

You can adjust to your needs and add array.
Thanks
Ruslan

Sent on the Now Network? from my SprintBlackBerry

-----Original Message-----
From: Cara Booker<< XXXX@XXXXX.COM >>
Date: Wed, 4 Nov 2009 12:51:40
To:<< XXXX@XXXXX.COM >>
Subject: Recode Variables

Hi,

I have a data set which is in long form. I have some variables (i.e. gender,
ethnicity) where the data is missing for specific waves, although I know the
values at baseline. I would like to copy the baseline value onto the rest of
the waves. Here is an example:

ID Wave Eth Sex
1 1 1 2
1 2 . .
1 3 . .
1 5 . .
2 1 2 1
2 2 . .
2 5 . .
2 7 . .

I would like it to look like:
ID Wave Eth Sex
1 1 1 2
1 2 1 2
1 3 1 2
1 5 1 2
2 1 2 1
2 2 2 1
2 5 2 1
2 7 2 1

Thank you,

Cara

sas >> Recode Variables

by Chris Jones » Wed, 04 Nov 2009 21:17:47 GMT


data want ;
set have ;
by id ;
retain _eth _sex ;

if first.id then do ;
_eth = eth ;
_sex = sex ;
end ;
else do ;
if missing(eth) then eth = _eth ;
if missing(sex) then sex = _sex ;
end ;
run ;

sas >> Recode Variables

by Ferndez Rodruez, » Wed, 04 Nov 2009 21:39:10 GMT

Hi Cara,

Other method is with a simple merge:


data need ;
merge
have (keep=id wave)
have(keep=id eth sex where=(nmiss(eth,sex)=0));
by id ;
run;


Daniel Fernandez.
Barcelona.




-----Mensaje original-----
De: SAS(r) Discussion [mailto: XXXX@XXXXX.COM ] En nombre de Ruslan Kirhizau
Enviado el: dimecres, 4 / novembre / 2009 14:09
Para: XXXX@XXXXX.COM
Asunto: Re: Recode Variables

Hi Cara,
You might want to try retain statement
Here is just an idea.

Data want;
Set have;
Retain _eth ;
If eth ne . then _eth = eth;
Eth = _eth;
Run;

You can adjust to your needs and add array.
Thanks
Ruslan

Sent on the Now Network? from my SprintBlackBerry

-----Original Message-----
From: Cara Booker<< XXXX@XXXXX.COM >>
Date: Wed, 4 Nov 2009 12:51:40
To:<< XXXX@XXXXX.COM >>
Subject: Recode Variables

Hi,

I have a data set which is in long form. I have some variables (i.e. gender,
ethnicity) where the data is missing for specific waves, although I know the
values at baseline. I would like to copy the baseline value onto the rest of
the waves. Here is an example:

ID Wave Eth Sex
1 1 1 2
1 2 . .
1 3 . .
1 5 . .
2 1 2 1
2 2 . .
2 5 . .
2 7 . .

I would like it to look like:
ID Wave Eth Sex
1 1 1 2
1 2 1 2
1 3 1 2
1 5 1 2
2 1 2 1
2 2 2 1
2 5 2 1
2 7 2 1

Thank you,

Cara

sas >> Recode Variables

by cbook76 » Wed, 04 Nov 2009 23:13:39 GMT

Thank you all for your replies. The retain statement worked like a charm.

Best,

Cara

Similar Threads

1. recode variable

Hello!

i'm looking for a solution for the following problem.
i have a dataset with a variable OLD and want the variable NEED.


old    need
AA       1
AA       1
AA       1
AD       2
AE       3
.        .
.        .
ZZ       100

my problem is that the number or variations of old can differ.

Thank you

Peter Mller

2. recoding variables with missing values

3. best way to flag recoded variable value

Hi. I have a large dataset and during data cleansing and recoding of certain 
variables, I would like to have a way to flag when a value changed during 
the process.  Is there a recommended or best-practice for doing something 
like this?  Typically, the value is pre-populated but for a myriad of 
reasons sometimes we need to force the code to another value.  The SAS code 
that changes the value of these variables can be lengthy and am unsure how 
to create the "switch" that flips if the value is changed during execution.

Any ideas?

~TIA 

4. recoding variables efficiently

5. Using input function to recode variables

If I run the following code, I get a message on the log:

NOTE: Numeric values have been converted to character values at the
places given by: (Line):(Column) [referring to the line with the input
function]

proc format;
  invalue recode 1=100 2=150 3=200;
data tempx;
do v=1 to 3;
  vrecode = input(v,recode.);
  put vrecode=;
end;
run;

Why is this? Does the input function convert the numeric variable v
back to character before using the informat? If so, what rules does it
follow for the conversion. Do I have to be on the lookout for
non-standard conversions?

6. Recoding Variables

7. Recode multiple variable into one variable

Dear all:

Please send me notes if you know how to solve this.

I have 6 variables (ULCER,SCAR,ACR,NEO, VAC, AEOT)
9 and are coded as 'Y' or 'N' , I would like it to be recoded into one
variable., say REASON with 6 values corresponding to the 6 variables
when ULCER,SCAR,ACR,NEO, VAC, AEOT are in ('Y')

here is my code. I wander if there are some other ways to do it? marco
or sql or else? thanks.

data a1;
  set me;
       if ulcer in ('Y','y') then do;
      ae_code =1; output;
       end;

       if scar in ('Y','y') then  do;
        ae_code =2; output;
      end;

        if acr in ('Y','y') then do;
        ae_code =3; output;
       end;

        if neo in ('Y','y') then do;
         ae_code =4; output;
        end;

       if va in ('Y','y') then do;
      ae_code =5; output;
      end;

        if aeot in ('Y','y') then do
        ae_code =6; output;
       end;
 run;

8. Recoding multiple variables