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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 493 views
  • 3 likes
  • 4 in conversation