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
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;
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.
You would have to post your data file in order to see what you actually have. A picture of it doesn't help much.
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.