BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bknitch
Quartz | Level 8

Data set is below.

 

I would like to retain the Max YEAR with the corresponding FIRST_FOUND detail. I've tried a retain statement but it seems its not working. Not sure if I am able to create a MAX(YEAR) within in a data step or if i will have to create that in a proc sql prior to performing my data step. Any assistance would be appreciated. 

 

Primary_IDSecondary_IDYEARCONDITIONSTATUSFIRST_FOUNDcount
1ABCDEFG234545672014108NEWIT0
1ABCDEFG234545672015108DROPPED 1
1ABCDEFG234545672016108DROPPED 2
1ABCDEFG234545672017108DROPPED 3
1ABCDEFG234545672018108DROPPED 4
1ABCDEFG234545672019108DROPPED 5

 

This is how i would like my data to look 

Primary_IDSecondary_IDDOS_YEARCONDITION STATUSFIRST_FOUNDcount
1ABCDEFG234545672018108NEWIT5

 

Code Below:

 

data source_detail_1 (keep=Primary_ID Secondary_ID YEAR CONDITION STATUS FIRST_FOUND COUNT YEAR1 );
set source_detail (where=(PRIMARY_ID='1ABCDEFG2345')) ;
retain first_found;
YEAR1= MAX(YEAR);
run;

1 ACCEPTED SOLUTION

Accepted Solutions
bknitch
Quartz | Level 8

Solved myself 

 

proc sort data=WORK.SOURCE_DETAIL; by primary_id year descending first_found ;run;
data temp1;
set WORK.SOURCE_DETAIL;
length first_found1 $3.;
retain first_found1 ;
by primary_id year descending first_found ;
if first.primary_id then do;
first_found1=first_found;
end;
output;
drop first_found;

run;

View solution in original post

1 REPLY 1
bknitch
Quartz | Level 8

Solved myself 

 

proc sort data=WORK.SOURCE_DETAIL; by primary_id year descending first_found ;run;
data temp1;
set WORK.SOURCE_DETAIL;
length first_found1 $3.;
retain first_found1 ;
by primary_id year descending first_found ;
if first.primary_id then do;
first_found1=first_found;
end;
output;
drop first_found;

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
  • 1 reply
  • 421 views
  • 0 likes
  • 1 in conversation