BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aliya-begum
Calcite | Level 5

data VS;
input ptid @5 vsdtc ddmmyy10. @17 result;
format vsdtc ddmmyy10.;
cards;
101 24/10/2018 110
101 25/10/2018 120
101 26/10/2018 115
101 27/10/2018 125
101 28/10/2018 135
102 23/10/2018 130
102 25/10/2018 120
102 26/10/2018 110
102 29/10/2018 115
102 30/10/2018 125
103 24/10/2018 120
103 26/10/2018 140
103 27/10/2018 110
103 28/10/2018 115
103 28/10/2018 145
;
run;

data DM;
input ptid @8 rfstdtc ddmmyy10.;
format rfstdtc ddmmyy10.;
cards;
101 26/10/2018
102 26/10/2018
103 27/10/2018
;
run;

proc sort data=VS;
by ptid;
run;
proc sort data=DM;
by ptid;
run;
data VS1;
merge VS DM;
by ptid;
run;
proc print;
run;

DATA VS2 VS3;
set VS1;
if vsdtc < rfstdtc then output VS2;
if vsdtc > rfstdtc then output VS3;
run;
DATA NEWL;
SET VS2;
IF LAST.result THEN vsblfl = 'Y';
RUN;
PROC PRINT;
RUN

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please avoid coding in upper case, its shouting code.  Missing by line:

data newl; 
  set vs2;
  by result;
  if last.result then vsblfl='Y';
run;

View solution in original post

6 REPLIES 6
Aliya-begum
Calcite | Level 5
its showing variable last.result is uninitialized.
error_prone
Barite | Level 11
If you want to use last(or first you have to use by, too. And I am wondering that you don't get a warning or at least a note saying exactly that.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please avoid coding in upper case, its shouting code.  Missing by line:

data newl; 
  set vs2;
  by result;
  if last.result then vsblfl='Y';
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
  • 6 replies
  • 1131 views
  • 0 likes
  • 4 in conversation