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

 

Dataset looks like this -

 

Name  ID  flag1

AJ      1     1

AJ      1     .

AJ      1     .

AJ      2     .

AJ      2     .

 

How do I make dataset looks like this -

 

Name  ID  flag1  varWant

AJ      1     1         1

AJ      1     .          1

AJ      1     .          1

AJ      2     .          .

AJ      2     .          .


Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Try this — assumes data is sorted by name and id.

 

data want;
    set have;
    retain varWant;
    by name id;
    if first.id and flag1=1 then varWant=1;
    if first.id and flag1^=1 then varWant=.;
run;
    
--
Paige Miller

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26
data want;
  set have;
  retain varwant;
  by name id;
  if first.name and first.id then varwan1;
run;
PaigeMiller
Diamond | Level 26

Try this — assumes data is sorted by name and id.

 

data want;
    set have;
    retain varWant;
    by name id;
    if first.id and flag1=1 then varWant=1;
    if first.id and flag1^=1 then varWant=.;
run;
    
--
Paige Miller
novinosrin
Tourmaline | Level 20
data have;
input Name $ ID  flag1;
cards;
AJ      1     1
AJ      1     .
AJ      1     .
AJ      2     .
AJ      2     .
;

data want;
set have;
by id;
retain varWant;
if first.id then do;
call missing(varwant);
if flag1 then varWant=flag1;
end;
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!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 876 views
  • 2 likes
  • 4 in conversation