- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi
I have dataset with
who_reacted_1 who_reacted_2----so on
1. 5556 5555
I want to calculate total number of who_reacted-if ID is 5555
who_reacted_1
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Like this ?
data have;
input id who_reacted_1 who_reacted_2 who_reacted_3 who_reacted_4 who_reacted_5;
datalines;
1 5556 5555 5555 5557 5555
;
run;
data want;
set have;
array who_reacted_(5);
do i=1 to dim(who_reacted_);
if who_reacted_(i) = 5555 then count+1;
end;
drop i;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks!
Do you how to include multiple ID's in the statement below-5555,5556,5557,
I am getting an error.
if who_reacted_(i) = 5555 then count+1;
end;
drop I;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @knargis160
Do you mean this ?
data have;
input who_reacted_1 who_reacted_2 who_reacted_3 who_reacted_4 who_reacted_5;
datalines;
5556 5555 5555 5557 5555
;
run;
data want;
set have;
array who_reacted_(5);
do i=1 to dim(who_reacted_);
if who_reacted_(i) in (5555,5556,5557) then count+1;
end;
drop i;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This code works but no error in coding but I am not getting actual number of reactions instead it is count from 1 to 30 observations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @knargis160
Could you please share some sample data as well as the expected output?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi sample data looks like this
input who_reacted_1 who_reacted_2 who_reacted_3 who_reacted_4 who_reacted_5.... who_reacted_40;
datalines;
5556 5555 5555 5557 5555
5556
5555 5556
5557
Output: Count
1
2
3... so on with code. It was working for single ID.
Does this makes more sense?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @knargis160
Is this better ?
-> count will give you the number of 'columns' who-react that were in 555 556 and 5557 for each row.
data have;
infile datalines dlm=" " dsd truncover;
input who_reacted_1 who_reacted_2 who_reacted_3 who_reacted_4 who_reacted_5;
datalines;
5556
5555 5556 5554 5557
5557 5554
;
run;
data want;
set have;
array who_reacted_(5);
count=0;
do i=1 to dim(who_reacted_);
if who_reacted_(i) in (5555,5556,5557) then count+1;
end;
drop i;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks it worked out
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I want to transpose the data
PTID who_reacted_1 who_reacted_2 who_reacted_3 who_reacted_4 who_reacted_5;
1 5556
2 5555 5556 5554 5557
3. 5557 5554
I want to have the data like
1. 5556
2. 5555
2. 5556
2.5554
2. 5557
Can you suggest a best way to figure that out?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
So if you have data like:
data have ;
input PTID who_reacted_1-who_reacted_5;
cards;
1 5556 . . . .
2 5555 5556 5554 5557 .
3 5557 5554 . . .
;
You just need to use BY statement in the PROC transpose. To get rid of the empty cells you can use a WHERE= dataset option on the output dataset.
proc tranpose data=have out=want (where=(not missing(col1));
by ptid;
var who_reacted_1-who_reacted_5;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Some how I am having col2, col3 as well. Do you know why
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@knargis160 wrote:
Some how I am having col2, col3 as well. Do you know why
Your BY variables do not uniquely identify the observations in your original dataset. You might have to add a new variable first if there is no combination of variables that work. Note you could actually use your first analysis variable and then just drop it from the output dataset.
Or just use the ARRAY method.
data want;
set have;
array who_reacted_[5] ;
do idx=1 to dim(who_reacted_);
value = who_reacted_[idx] ;
if not missing(value) then output;
end;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks it worked!
Do you know if I can categorize in these ID's in array statement
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How did you get counts of 1,2,3? I see counts of 5,1,2,1.