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

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
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;
sidpesar
Obsidian | Level 7

%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);

abc44
Obsidian | Level 7

Thank you! Both solutions worked perfectly!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

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
  • 645 views
  • 2 likes
  • 3 in conversation