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     .

 

How do I make dataset looks like this -

 

Name  ID  flag1.  varWant

AJ      1     1         1

AJ      1     .          1

AJ      1     .          1

AJ      2     .          .


Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

As long as your data set is sorted by Name and ID:

 

data want;

set have;

by name id;

if first.id or flag1 > . then varWant = flag;

retain varWant;

run;

View solution in original post

2 REPLIES 2
KPCklebspn
Obsidian | Level 7

To clarify - I want the first obs for flag within a group (name AND ID) to carry down

Astounding
PROC Star

As long as your data set is sorted by Name and ID:

 

data want;

set have;

by name id;

if first.id or flag1 > . then varWant = flag;

retain varWant;

run;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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
  • 2 replies
  • 849 views
  • 0 likes
  • 2 in conversation