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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 478 views
  • 3 likes
  • 4 in conversation