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

Hello,

 

I have 9 records that contain missing SI values (in 10^9/L - LBSTRESU) for paramcd= 'EOS' test while raw values (in % unit- LBORRES) are provided,  I would need to add the following derivation to  convert values to the SI units in my analysis dataset (variable AVAL ) to handle the missing values while raw values (in % unit) are provided:

 

EOS (SI unit, 10^9/L, Column AVAL) = WBC (10^9/L, Column AVAL from WBC test at the same time/visit - AVISIT) x EOS in percentage % (Column LBORRES from EOS test at the same time/visit - AVISIT) , where WBC is the lab result from the same patient at the same time/visit (i.e., both WBC and EOS are collected at the same time - AVISIT).

 

current data (green are missing - need calculated values):

HitmonTran_0-1746501086417.png

 

 

want (calculated values are color-coded. Previously green colored - eg 4.5 * .04 = 0.18)

HitmonTran_0-1746499947528.png

 

attached is the data in excel format (sheet 3)

 

 

Thank you very much!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

That would be very easy as long as your data structure looks like what you showed. (a.ka. two obs for each subject and each visit ,first is k/ul ,second is %)

 

data have;
input subject param $ visit aval lb;
cards;
1 WBC 1 4.5 4.5
1 EOD 1 .   4
1 WBC 2 8.1 8.1
1 EOD 2 .   0.2
2 WBC 1 4.5 4.5
2 EOD 1 .   2
2 WBC 2 8.1 8.1
2 EOD 2 .   0.2
;
data want;
 set have;
 lag_aval=lag(aval);
 if missing(aval) then aval=lag_aval*lb*0.01;
 drop lag_aval;
run;


View solution in original post

2 REPLIES 2
mkeintz
PROC Star

In the absence of sample data in the form of a working DATA step, here is untested code.

 

This code assumes every EOS record is preceded by a matching WBC record:

data want;
  set have;
  array var     aval    anrlo     anrhi;
  array pct     lborres lbornrlo  lborrnrhi;

  do over var;
    var=ifn(param='EOS',sum(0,lag(var))*pct/100,var);
  end;
run;

The reason for the "sum(0,lag(var))" expression is to avoid an error message with the first observation, for which lag(var) is missing, and therefore would cause a missing value result when multiplied by "pct/100").

 

You could test for matching WBC record with something like:

 

data want;
  set have;
  array var     aval    anrlo     anrhi;
  array pct     lborres lbornrlo  lborrnrhi;

  do over var;
    var=ifn(param='EOS' and lag(param)='WBC' 
              and subjid=lag(subjid) and avisit=lag(avisit)
           ,sum(0,lag(var))*pct/100
           ,var);
  end;
run;

Again, untested.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Ksharp
Super User

That would be very easy as long as your data structure looks like what you showed. (a.ka. two obs for each subject and each visit ,first is k/ul ,second is %)

 

data have;
input subject param $ visit aval lb;
cards;
1 WBC 1 4.5 4.5
1 EOD 1 .   4
1 WBC 2 8.1 8.1
1 EOD 2 .   0.2
2 WBC 1 4.5 4.5
2 EOD 1 .   2
2 WBC 2 8.1 8.1
2 EOD 2 .   0.2
;
data want;
 set have;
 lag_aval=lag(aval);
 if missing(aval) then aval=lag_aval*lb*0.01;
 drop lag_aval;
run;


sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 397 views
  • 0 likes
  • 3 in conversation