BookmarkSubscribeRSS Feed
rashmirao99
Fluorite | Level 6

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.

3 REPLIES 3
Kurt_Bremser
Super User

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"?

rashmirao99
Fluorite | Level 6

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.

Kurt_Bremser
Super User

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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 3 replies
  • 717 views
  • 0 likes
  • 2 in conversation