- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How do I count the number of times the value A or T appears for each record. I want to enter the count into either column TSA_Count_A or TSA_Count_T as applicable?
ID | TSA_1 | TSA_2 | TSA_3 | TSA_4 | TSA_COUNT_ A | TSA_COUNT_T |
123 | A | T | A | T |
|
|
456 | T | T | N | A |
|
|
789 | T | N | A | T |
|
|
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
infile cards truncover;
input (ID T1-T4) ($);
cards;
123 A T A T
456 T T N A
789 T N A T
;
data want;
set have;
TSA_COUNT_A=countc(cats(of t1-t4),'A');
TSA_COUNT_T=countc(cats(of t1-t4),'T');
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
infile cards truncover;
input (ID T1-T4) ($);
cards;
123 A T A T
456 T T N A
789 T N A T
;
data want;
set have;
TSA_COUNT_A=countc(cats(of t1-t4),'A');
TSA_COUNT_T=countc(cats(of t1-t4),'T');
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you!
I created an array and it worked.
ARRAY TSA_RESULT {4} TSA_1-TSA_4;
TSA_COUNT_A = COUNTC(CATS(OF TSA_1-TSA_4), 'A');
TSA_COUNT_T = COUNTC(CATS(OF TSA_1-TSA_4), 'T');
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@AP101 wrote:
Thank you!
I created an array and it worked.
ARRAY TSA_RESULT {4} TSA_1-TSA_4;
TSA_COUNT_A = COUNTC(CATS(OF TSA_1-TSA_4), 'A');
TSA_COUNT_T = COUNTC(CATS(OF TSA_1-TSA_4), 'T');
Adding the array statement shouldn't have made any difference.
The only case I think were is would make a difference is if the input dataset had only some of the variables.
Then the ARRAY statement will insure that the added variables are of the same type as those that were present.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That's good to know. I thought I had to add it for the 1-4. I ran it without and still the same. Thanks!