I have a table where each biomarker has a corresponding flag variable that equals 1 if it needs to be reviewed. Is there a way to systematically output the SUBJECTID and the biomarker name and value if the variable is flagged?
data have;
input SUBJECTID $ BLD_GGT BLD_TRIG BLD_INS BLD_GGT_FLAG BLD_TRIG_FLAG BLD_INS_FLAG;
cards;
001 12 100 43 0 0 1
002 12 99 42 0 0 0
003 15 104 30 0 0 0
004 3 109 24 1 1 0
005 14 100 23 0 0 0
;
run;
data want;
input SUBJECTID $ VARIABLE $ VALUE;
cards;
001 BLD_INS 43
004 BLD_GGT 15
004 BLD_TRIG 109
;
run;
Try next code:
data want;
set have;
length variable $15; /* addapt to max variable name length */
array flg BLD_GGT_FLAG BLD_TRIG_FLAG BLD_INS_FLAG;
array bio BLD_GGT BLD_TRIG BLD_INS;
do i=1 to dim(flg);
if flg(i)=1 then do;
variable = vname(bio(i));
value = bio(i);
output;
end;
end;
keep subjectid variable value;
run;
Hi @bkq32 Methinks your HAVE has value ambiguity or a typo. So i modified your HAVE with that assumption
data have;
input SUBJECTID $ BLD_GGT BLD_TRIG BLD_INS BLD_GGT_FLAG BLD_TRIG_FLAG BLD_INS_FLAG;
cards;
001 12 100 43 0 0 1
002 12 99 42 0 0 0
003 15 104 30 1 0 0
004 3 109 24 0 1 0
005 14 100 23 0 0 0
;
run;
data want;
set have;
array b BLD_GGT BLD_TRIG BLD_INS;
array f BLD_GGT_FLAG BLD_TRIG_FLAG BLD_INS_FLAG;
_n_=whichn(1,of f(*));
if _n_;
variable=vname(b(_n_));
value=b(_n_);
keep subjectid variable value;
run;
Hi @novinosrin, The original HAVE table was correct since some records will have more than one flag, in which case I'd like to create separate records for them in WANT with the variable name and value for each of those biomarkers. Is there a way to do that?
@novinosrin A clinician might've told me to run something like:
if BLD_GGT>14 then BLD_GGT_FLAG=1;
Try next code:
data want;
set have;
length variable $15; /* addapt to max variable name length */
array flg BLD_GGT_FLAG BLD_TRIG_FLAG BLD_INS_FLAG;
array bio BLD_GGT BLD_TRIG BLD_INS;
do i=1 to dim(flg);
if flg(i)=1 then do;
variable = vname(bio(i));
value = bio(i);
output;
end;
end;
keep subjectid variable value;
run;
Thank you, @Shmuel. When I tried running that code, I go this error:
411 data want;
412 set have;
413 length variable $15; /* addapt to max variable name
413! length */
414 array flg BLD_GGT_FLAG BLD_TRIG_FLAG BLD_INS_FLAG;
415 array bio BLD_GGT BLD_TRIG BLD_INS;
416 do i=1 to dim(flgs);
ERROR: The DIM, LBOUND, and HBOUND functions require an array
name for the first argument.
417 if flg(i)=1 then do;
418 variable = vname(bio(i));
419 value = bio(i);
420 output;
421 end;
422 end;
423 keep subjectid variable value;
424 run;
The array name is flg not flgs - tat was my typo;
change line to
do i=1 to dim(flg);
-
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.