BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lavienrose1
Calcite | Level 5

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 
1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

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

4 REPLIES 4
Shmuel
Garnet | Level 18

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 ?

lavienrose1
Calcite | Level 5

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

Shmuel
Garnet | Level 18

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;

 

 

lavienrose1
Calcite | Level 5

Thank you Shmuel - that worked

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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