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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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