BookmarkSubscribeRSS Feed
rashmirao99
Fluorite | Level 6

Hi I have data like this:

 

Subjid         visitdt             kitno

201-001     2019-08-21    1001

201-001        

201-001

201-001

210-001   2019-09-21    1003

I need to create another column called ecref and the result should look like this:

Subjid         visitdt             kitno     ecref

201-001     2019-08-21    1001     1001

201-001                                         1001

201-001                                          1001

201-001                                          1001

210-001   2019-09-21    1003         1003

 

Thanks.

 

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Please provide a meaningful title that describes the problem. A title like "Help with SAS code" applies to almost every problem.

--
Paige Miller
biopharma
Quartz | Level 8

Agree with the other poster that you have to provide a meaningful description of your problem. Look up the documentation for RETAIN. Then take care to reset ECREF to a missing value for each SUBJID. You do have your data already sorted correctly by SUBJID and another ID field like a record number or a sequence number within each subject, right? So something along the lines as below should work (UNTESTED).

 

data want ;

    set have ;

    by subjid ;

    retain ecref ;

    if first.subjid then ecref = . ;

    if not missing(kitno) then ecref = kitno ;

run ;

 

 

Sathish_jammy
Lapis Lazuli | Level 10

Use the below code.

 

data want;
set have;
by Subjid;
retain ecref;
if kitno ne . then ecref = kitno;
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 Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 586 views
  • 3 likes
  • 4 in conversation