Hi all,
I have data that looks like following:
ID T1 T2 T3 T4 T1_C T2_C T3_C T4_C
1 5.1 6.4 6.3 7.1 100 34 74 98
2 6.3. 7.2 7.8 8.1 100 97 33 48
3 5.6. 6.7 7.7 8.3 98 99 96 100
I would like to delete observations for T1, T2, T3, or T4 if the corresponding compliance is less than 50 (T1_C, T2_C, T3_C, T4_C).
ID T1 T2 T3 T4 T1_C T2_C T3_C T4_C
1 5.1 . 6.3 7.1 100 34 74 98
2 6.3. 7.2 . 8.1 100 97 33 48
3 5.6. 6.7 7.7 8.3 98 99 96 100
Since T2_C and T3_C is <50 I would like to delete T2 for ID 1, and T3 for ID 2. ID3 has compliance values above 50 at all time points, so no observations should be deleted.
Please let me know if you have any suggestions! I am relatively new to SAS and haven't been successful in figuring this one out.
Thanks in advance!
data have;
infile cards truncover;
input ID T1 T2 T3 T4 T1_C T2_C T3_C T4_C;
cards;
1 5.1 6.4 6.3 7.1 100 34 74 98
2 6.3 7.2 7.8 8.1 100 97 33 48
3 5.6 6.7 7.7 8.3 98 99 96 100
;
data want;
set have;
array t_ t:;
array tt_ t1_c--t4_c;
do over tt_;
if tt_<50 then t_=.;
end;
run;
data have;
infile cards truncover;
input ID T1 T2 T3 T4 T1_C T2_C T3_C T4_C;
cards;
1 5.1 6.4 6.3 7.1 100 34 74 98
2 6.3 7.2 7.8 8.1 100 97 33 48
3 5.6 6.7 7.7 8.3 98 99 96 100
;
data want;
set have;
array t_ t:;
array tt_ t1_c--t4_c;
do over tt_;
if tt_<50 then t_=.;
end;
run;
%macro run_test(t_values=);
data want;
set have;
%do i=1 %to &t_values. ;
if t&i._c < 50 then t&i=.; else t&i=t&i;
%end;
run;
%mend;
%run_test(t_values=4);
Thank you! Both solutions worked perfectly!
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 25. Read more here about why you should contribute and what is in it for you!
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.