Hi,
I need help with ADAM data ADLB. I need to create a flag variable:
The condition is: If a subject has 4 paramcd has 4 aval values which are same I need to flag the first record as Y. For eample:
paramcd aval Flag
alb 4 Y
alb 4
alb 4
alb 4
Hope this is clear.
Thanks
Rashmi.
If you run this code:
data have;
input paramcd $ aval;
datalines;
alb 4
alb 4
alb 4
alb 4
xxx 1
xxx 2
xxx 2
xxx 2
xxx 2
xxx 2
yyy 1
yyy 2
yyy 3
yyy 2
yyy 2
yyy 2
yyy 3
zzz 1
zzz 2
zzz 2
zzz 3
zzz 2
zzz 2
zzz 2
zzz 3
zzz 3
zzz 3
zzz 3
;
which of the observations should be flagged "Y"?
it should flag like this: it should flag only when all the values for paramcd are equal.
alb 4 Y
alb 4
alb 4
alb 4
xxx 1
xxx 2
xxx 2
xxx 2
xxx 2
xxx 2
yyy 1
yyy 2
yyy 3
yyy 2
yyy 2
yyy 2
yyy 3
zzz 1
zzz 2
zzz 2
zzz 3
zzz 2
zzz 2
zzz 2
zzz 3
zzz 3
zzz 3
zzz 3
Thanks.
Then run this code, based on my earlier "have" dataset:
proc sql;
create table flag as
select
paramcd,
case
when count(distinct aval) = 1
then 'Y'
else ' '
end as flag
from have
group by paramcd
having flag = 'Y';
quit;
data want;
merge
have
flag
;
by paramcd;
if not first.paramcd then flag = ' ';
run;
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.