Dear,
I need help in my pgm. Please suggest in my code to get output. Thank you
For id=2 and 3, have missing visits. I need to have each subject all possible visits records.
2 in this dataset.
output need;
id visit visitn
1 Post1 Cycle 4 12
1 Post2 Cycle 4 18
2 Post1 Cycle 4 12
2 Post2 Cycle 4 18
3 Post1 Cycle 4 12
3 Post2 Cycle 4 18
4 Post1 Cycle 4 12
4 Post2 Cycle 4 18
data one;
input id visit $3-16 visitn;
datalines;
1 Post1 Cycle 4 12
1 Post2 Cycle 4 18
2 Post1 Cycle 4 12
3 Post2 Cycle 4 18
4 Post1 Cycle 4 12
4 Post2 Cycle 4 18
;
proc sql noprint;
create table tmp1 as
select distinct id,visit
from one;
quit;
data tmp2;
set tmp1;
do visitn= 12, 18; output; end;
run;
data want;
merge one tmp2;
by id visit visitn;
run;
I usually try to resist atavistic impulses to use sql, but here is a situation that I think sql stands up well:
data one;
input id visit $3-16 visitn;
datalines;
1 Post1 Cycle 4 12
1 Post2 Cycle 4 18
2 Post1 Cycle 4 12
3 Post2 Cycle 4 18
4 Post1 Cycle 4 12
4 Post2 Cycle 4 18
;
proc sql;
create table want as
select id, visit, visitn
from
(select distinct id from one)
cross join
(select distinct visit,visitn from one) ;
quit;
You can relatively easily expand this to more than 2 groups of variables. In this case group1 is ID, group 2 is visit*visitn.
Editted change:
modified
(select distinct id from one)
join
(select distinct visit,visitn from one) on 1 ;
to
(select distinct id from one)
cross join
(select distinct visit,visitn from one) ;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.