BookmarkSubscribeRSS Feed
thanikondharish
Calcite | Level 5

subid

Date

Dose

P101

13JAN2005

Asp-05mg

P101

19JAN2005

Asp-10mg

P101

25JAN2005

Asp-15mg

P101

31JAN2005

 

P102

14JAN2005

Asp-10mg

P102

20JAN2005

Asp-05mg

P102

26JAN2005

Asp-15mg

P102

01FEB2005

Asp-15mg

P103

19JAN2005

Asp-15mg

P103

25JAN2005

Asp-10mg

P103

30JAN2005

Asp-10mg

P104

26JAN2005

Asp-10mg

P104

02FEB2005

Asp-10mg

P105

02FEB2005

Asp-20mg

 

derive every group last record without missing like see below dataset

subid

Date

Dose

P101

25JAN2005

Asp-15mg

P102

01FEB2005

Asp-15mg

P103

30JAN2005

Asp-10mg

P104

02FEB2005

Asp-10mg

P105

02FEB2005

Asp-20mg

7 REPLIES 7
PaigeMiller
Diamond | Level 26

Two step process

 

  1. Delete records with missing values
  2. Use the LAST. structure in a SAS data step to find the last record in each group https://documentation.sas.com/?docsetId=lrcon&docsetTarget=n01a08zkzy5igbn173zjz82zsi1s.htm&docsetVe...
--
Paige Miller
thanikondharish
Calcite | Level 5
yes i did what you mentioned like two step process
is there any method in single step
thanikondharish
Calcite | Level 5
without using where condition
error_prone
Barite | Level 11

@thanikondharish wrote:
without using where condition

Why?

Kurt_Bremser
Super User

If you want to act on a condition, you need to program it. Don't be an idiot here.

data have;
infile cards truncover;
input subid :$4. date: date9. dose :$8.;
format date date9.;
cards;
P101 13JAN2005 Asp-05mg
P101 19JAN2005 Asp-10mg
P101 25JAN2005 Asp-15mg
P101 31JAN2005 
P102 14JAN2005 Asp-10mg
P102 20JAN2005 Asp-05mg
P102 26JAN2005 Asp-15mg
P102 01FEB2005 Asp-15mg
P103 19JAN2005 Asp-15mg
P103 25JAN2005 Asp-10mg
P103 30JAN2005 Asp-10mg
P104 26JAN2005 Asp-10mg
P104 02FEB2005 Asp-10mg
P105 02FEB2005 Asp-20mg
;
run;

data want;
set have (where=(dose ne ''));
by subid;
if last.subid;
run;

proc print data=want noobs;
run;

Result:

subid         date      dose

P101     25JAN2005    Asp-15mg
P102     01FEB2005    Asp-15mg
P103     30JAN2005    Asp-10mg
P104     02FEB2005    Asp-10mg
P105     02FEB2005    Asp-20mg

Problem solved, case closed.

Ksharp
Super User

Is there any reason you are unable to use WHERE ? or just want check our sas skill ?

 

data have;
infile cards truncover;
input subid :$4. date: date9. dose :$8.;
format date date9.;
cards;
P101 13JAN2005 Asp-05mg
P101 19JAN2005 Asp-10mg
P101 25JAN2005 Asp-15mg
P101 31JAN2005 
P102 14JAN2005 Asp-10mg
P102 20JAN2005 Asp-05mg
P102 26JAN2005 Asp-15mg
P102 01FEB2005 Asp-15mg
P103 19JAN2005 Asp-15mg
P103 25JAN2005 Asp-10mg
P103 30JAN2005 Asp-10mg
P104 26JAN2005 Asp-10mg
P104 02FEB2005 Asp-10mg
P105 02FEB2005 Asp-20mg
;
run;
data want;
 do i=1 by 1 until(last.subid);
   set have;
   by subid;
   if not missing(dose) then _i=i;
 end;
 do i=1 by 1 until(last.subid);
   set have;
   by subid;
   if _i=i then output;
 end;
 drop i _i;
 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
  • 7 replies
  • 833 views
  • 0 likes
  • 5 in conversation