BookmarkSubscribeRSS Feed
jcabrera
Calcite | Level 5

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

4 REPLIES 4
art297
Opal | Level 21

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

data anova_03bb (drop=last:);

  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;

jcabrera
Calcite | Level 5

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

art297
Opal | Level 21

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

art297
Opal | Level 21

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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