Help using Base SAS procedures

How to merge two variables together?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

How to merge two variables together?

Hi,

 

After transposing my long dataset to wide, I realised some variables were the same but titled differently (one is serum, and the other plasma). So now I would like to clean my data further by merging the variables but having trouble with the coding. 

 

For example (see sample data below):

For subject E01, I would like to put the data for 'var_Alanine_Aminotransferase__P' under the first variable 'var_Alanine_Aminotransferase__Se' and delete 'var_Alanine_Aminotransferase__P' . Similarly, I would like to put the data under 'var_Alkaline_Phosphatase__Plasma' under the 3rd variable 'var_Alkaline_Phosphatase__Serum_'.

 

What is the best way to go about doing this? Thanks in advance.

 

 

SUBJECTvar_Alanine_Aminotransferase__Sevar_Albumin__Serum_var_Alkaline_Phosphatase__Serum_var_Aspartate_Aminotransferase__var_Bilirubin__Total__Serum_var_Calcium__Serum_var_Carbohydrate_Antigen_125__Sevar_Creatinine__Serum_var_Gamma_Glutamyltransferase__Svar_Hemoglobin__Blood_var_Lactate_Dehydrogenase__Serumvar_Leucocytes__Particle_Concentvar_Lymphocytes__Particle_Concenvar_Neutrophils__Particle_Concenvar_Platelets__Particle_Concentrvar_Protein__Total__Serum_var_Alanine_Aminotransferase__Plvar_Alkaline_Phosphatase__Plasmavar_Bilirubin__Total__Plasma_var_Calcium__Plasma_var_Creatinine__Plasma_var_Gamma_Glutamyltransferase__Pvar_Lactate_Dehydrogenase__Plasmvar_Lymphocytes__Blood_var_Protein__Total__Plasma_var_Albumin__Plasma_
E0227431293462.54568291222417.32.53.817575          
E01   26  39  115 5.112.52.2187 37723.2492.3683.981823149.774 

Accepted Solutions
Solution
‎04-23-2018 02:06 AM
Trusted Advisor
Posts: 1,837

Re: How to merge two variables together?

Posted in reply to lavienrose1

Use next code to do the work:

data want

 set have;

       array x_serum var_Alanine_Aminotransferase__Se var_Albumin__Serum_ ..... <up to the last ..._srum>;

       array x_plasma var_Alanine_Aminotransferase__Pl  var_Alkaline_Phosphatase__Plasma ..... <up to last ..._plasma>;

       **** Be careful to order both arrays in compatible order !  ***;

 

     do i=1 to dim(x_serum);

          if x_plasma(i) ne .    /* missing value */

          then x_serum(i) = x_plasma(i);

    end;

 

    drop i  x_plasma var_Alanine_Aminotransferase__Pl  var_Alkaline_Phosphatase__Plasma ..... <up to last ..._plasma>;

run;

 

 

View solution in original post


All Replies
Trusted Advisor
Posts: 1,837

Re: How to merge two variables together?

Posted in reply to lavienrose1

If I understand it correctly you have an array of _serum compatible to array of _plasma

and you want to move the last into the first then drop the last array variables.

Is it correct ?

Can both variables xxx_serum and xxx_plasma be non empty ? - If positive, what do you want to do?

replace the value or save both in separate oservations ?

Occasional Contributor
Posts: 18

Re: How to merge two variables together?

If I understand it correctly you have an array of _serum compatible to array of _plasma

and you want to move the last into the first then drop the last array variables.

Is it correct ? 

Yes that is the correct understanding

 

Can both variables xxx_serum and xxx_plasma be non empty ? - If positive, what do you want to do?

replace the value or save both in separate oservations ? 

I would replace the value 

 

Thanks

Solution
‎04-23-2018 02:06 AM
Trusted Advisor
Posts: 1,837

Re: How to merge two variables together?

Posted in reply to lavienrose1

Use next code to do the work:

data want

 set have;

       array x_serum var_Alanine_Aminotransferase__Se var_Albumin__Serum_ ..... <up to the last ..._srum>;

       array x_plasma var_Alanine_Aminotransferase__Pl  var_Alkaline_Phosphatase__Plasma ..... <up to last ..._plasma>;

       **** Be careful to order both arrays in compatible order !  ***;

 

     do i=1 to dim(x_serum);

          if x_plasma(i) ne .    /* missing value */

          then x_serum(i) = x_plasma(i);

    end;

 

    drop i  x_plasma var_Alanine_Aminotransferase__Pl  var_Alkaline_Phosphatase__Plasma ..... <up to last ..._plasma>;

run;

 

 

Occasional Contributor
Posts: 18

Re: How to merge two variables together?

Thank you Shmuel - that worked

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 193 views
  • 0 likes
  • 2 in conversation