SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Matching by variables when values repeat

Reply
Occasional Contributor
Posts: 10

Matching by variables when values repeat

Hello,

I would like to make my dataset "anova_3b" look like "anova_3bb" (see attached picture). I know I can't merge by cohort/attention because there are more than one observation per combination. Could you please shed some light on how I can tranform my dataset?

Thank you,

Juan

PROC Star
Posts: 7,487

Re: Matching by variables when values repeat

If I correctly understand how you are trying to collapse your data wouldn't something like the following work?:

data anova_03bb (drop=lastSmiley Happy;

  set anova_03b;

  last_trial=lag(trial);

  last_extremity_1=lag(extremity_1);

  last_extremity_0=lag(extremity_0);

  if mod(_n_,2) eq 0 then do;

    if missing(extremity_1) then do;

      trial=last_trial;

      extremity_1=last_extremity_1;

    end;

    else extremity_0=last_extremity_0;

    output;

  end;

run;

Occasional Contributor
Posts: 10

Re: Matching by variables when values repeat

Arthur,

Thank you very much for looking into this. The code you gave me creates some missing observations where there should be a data value. I tried to work with it and find the reason but I could not figure it out. Below is the dataset resulting from running the code you provided me with (there should be 24 obs for Extremity_0 and 24 obs for Extremity_1) . Thanks again for looking into this.

doc1.jpg

PROC Star
Posts: 7,487

Re: Matching by variables when values repeat

You would have to post your data file in order to see what you actually have. A picture of it doesn't help much.

PROC Star
Posts: 7,487

Re: Matching by variables when values repeat

Actually, as I look more closely at your original example, the problem might be a lot easier. Does the following do what you want?:

data anova_03b0 (keep=extremity_0) anova_03b1 (drop=extremity_0);

  set anova_03b;

  if missing(extremity_1) then output anova_03b0;

  else output anova_03b1;

run;

data anova_03bb;

  set anova_03b1;

  set anova_03b0;

run;

Ask a Question
Discussion stats
  • 4 replies
  • 529 views
  • 0 likes
  • 2 in conversation