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

Hi everyone, i got the next dataset:

    visit       phase

  baseline   1

  week2      2

  week4      2

  week6      1

  baseline   2

  week2      1

  week4      1

  week6      1

I want something like this

visit        phase   visit_b     phase_b

  baseline   1       baseline    1

  week2      2     baseline    1

  week4       2    baseline    1

  week6      1     baseline    1

  baseline   2     baseline    2

  week2      1    baseline     2

  week4      1    baseline     2

  week6      1    baseline     2


Any help...maybe with the retain function...thanks in advance.

V

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

Yes, you can use retain:

data have;

input (visit phase) (:$);

cards;

  baseline 1

  week2 2

  week4 2

  week6 1

  baseline 2

  week2 1

  week4 1

  week6 1

  ;

data want;

set have;

if visit='baseline' then do;

  visit_b=visit;

phase_b=phase;

end;

retain visit_b phase_b;

run;

Or not: (variables from table are automatically retained)

data want;

if 0 then set have (rename=(phase=phase_b visit=visit_b));

set have;

if visit='baseline' then do;

  visit_b=visit;

phase_b=phase;

end;

run;

Or not using retain and silly: (temporary array are automatically retained)

data want;

set have;

array _v(2) $ _temporary_;

array _b $ visit_b phase_b;

if visit='baseline' then do;

  _v(1)=visit;

  _v(2)=phase;

  end;

  do _n_=1 to dim(_b);

  _b(_n_)=_v(_n_);

  end;

run;

Haikuo

View solution in original post

3 REPLIES 3
Haikuo
Onyx | Level 15

Yes, you can use retain:

data have;

input (visit phase) (:$);

cards;

  baseline 1

  week2 2

  week4 2

  week6 1

  baseline 2

  week2 1

  week4 1

  week6 1

  ;

data want;

set have;

if visit='baseline' then do;

  visit_b=visit;

phase_b=phase;

end;

retain visit_b phase_b;

run;

Or not: (variables from table are automatically retained)

data want;

if 0 then set have (rename=(phase=phase_b visit=visit_b));

set have;

if visit='baseline' then do;

  visit_b=visit;

phase_b=phase;

end;

run;

Or not using retain and silly: (temporary array are automatically retained)

data want;

set have;

array _v(2) $ _temporary_;

array _b $ visit_b phase_b;

if visit='baseline' then do;

  _v(1)=visit;

  _v(2)=phase;

  end;

  do _n_=1 to dim(_b);

  _b(_n_)=_v(_n_);

  end;

run;

Haikuo

michtka
Fluorite | Level 6

Thanks Hai, I will use the first one with retain. Smiley Happy

data_null__
Jade | Level 19

Since you will surely have SUBJECTS or other grouping you will want INIT TO MISSING when a new subject is started to handle the possibility that a subject has no baseline. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1282 views
  • 0 likes
  • 3 in conversation