BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
smackerz1988
Pyrite | Level 9

Hello,

I'm creating a parameter for a dataset and for each result (AVAL) there is a particular strategy (Composite Strategy 2). For this one I need to impute the AVAL from the last visit (DTYPE=LOV) (In this case Early termination and if an AVAL is present in that visit I need to use that AVAL for previous visits where AVAL is missing. My question is how do I do a double DOW loop to achieve this and get the missing AVAL records to populate with the AVAL from the Early Termination visit but without overwriting any visits where AVAL is present (In this example data the Week 2 AVAL). Here is a snippet of my current dataset and my desired output

 

 

data have;
input  PARAMCD $ STRATEGY :$30. DTYPE $ SUBJID $ VISIT :$30. AVAL :8.; 
infile datalines dlm = '|';
datalines;
TOTEDPS1|Composite strategy 2|LOV|1001|Week 2|61.2
TOTEDPS1|Composite strategy 2|LOV|1001|Week 4|
TOTEDPS1|Composite strategy 2|LOV|1001|Week 8|
TOTEDPS1|Composite strategy 2|LOV|1001|Week 12|
TOTEDPS1|Composite strategy 2|LOV|1001|Week 16|
TOTEDPS1|Composite strategy 2|LOV|1001|Early Termination|43.5
TOTEDPS1|Composite strategy 2|LOV|1002|Week 2|16
TOTEDPS1|Composite strategy 2|LOV|1002|Week 4|
TOTEDPS1|Composite strategy 2|LOV|1002|Week 8|
TOTEDPS1|Composite strategy 2|LOV|1002|Week 12|
TOTEDPS1|Composite strategy 2|LOV|1002|Week 16|
TOTEDPS1|Composite strategy 2|LOV|1002|Early Termination|6.6
;
run;

data want;
input  PARAMCD $ STRATEGY :$30. DTYPE $ SUBJID $ VISIT :$30. AVAL :8.; 
infile datalines dlm = '|';
datalines;
TOTEDPS1|Composite strategy 2|LOV|1001|Week 2|61.2
TOTEDPS1|Composite strategy 2|LOV|1001|Week 4|43.5
TOTEDPS1|Composite strategy 2|LOV|1001|Week 8|43.5
TOTEDPS1|Composite strategy 2|LOV|1001|Week 12|43.5
TOTEDPS1|Composite strategy 2|LOV|1001|Week 16|43.5
TOTEDPS1|Composite strategy 2|LOV|1001|Early Termination|43.5
TOTEDPS1|Composite strategy 2|LOV|1002|Week 2|16
TOTEDPS1|Composite strategy 2|LOV|1002|Week 4|6.6
TOTEDPS1|Composite strategy 2|LOV|1002|Week 8|6.6
TOTEDPS1|Composite strategy 2|LOV|1002|Week 12|6.6
TOTEDPS1|Composite strategy 2|LOV|1002|Week 16|6.6
TOTEDPS1|Composite strategy 2|LOV|1002|Early Termination|6.6
;
run;

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
smackerz1988
Pyrite | Level 9

Actually figured it out myself. Here is the code for anyone interested.

 

data want;
do _n_ = 1 by 1 until(last.usubjid);
  set have;
  by usubjid;
  if visit ='Early Termination' and not(missing(aval)) then last_non_missing = aval;
end;
do _n_ = 1 to _n_;
  set have;  
  aval =coalesce(aval,last_non_missing);
  output;
end;
drop last_non_missing;
run;

View solution in original post

1 REPLY 1
smackerz1988
Pyrite | Level 9

Actually figured it out myself. Here is the code for anyone interested.

 

data want;
do _n_ = 1 by 1 until(last.usubjid);
  set have;
  by usubjid;
  if visit ='Early Termination' and not(missing(aval)) then last_non_missing = aval;
end;
do _n_ = 1 to _n_;
  set have;  
  aval =coalesce(aval,last_non_missing);
  output;
end;
drop last_non_missing;
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
  • 1 reply
  • 281 views
  • 1 like
  • 1 in conversation