I have an analysis flag variable specification
Set to "Y" for all records across a subject/parameter category (USUBJID/PARCAT1N) that has at least one record where A1IND is "High", or A2IND is "Change high". |
Here is a sample of the data and highlighted in red the desired output
USUBJID | A1IND | PARAMCD | ADT | ANL03FL |
1001 | Within range | SYSBP | 20Apr2022 | |
1001 | Within range | SYSBP | 10May2022 | |
1001 | Within range | SYSBP | 26May2022 | |
1001 | Within range | SYSBP | 01Jun2022 | |
1001 | High | DIABP | 20Apr2022 | Y |
1001 | Within range | DIABP | 10May2022 | Y |
1001 | Within range | DIABP | 26May2022 | Y |
1001 | Within range | DIABP | 01Jun2022 | Y |
1001 | No criteria defined for parameter | HR | 20Apr2022 | |
1001 | No criteria defined for parameter | HR | 10May2022 | |
1001 | No criteria defined for parameter | HR | 26May2022 | |
1001 | No criteria defined for parameter | HR | 01Jun2022 | |
1001 | No criteria defined for parameter | RESP | 20Apr2022 | |
1001 | No criteria defined for parameter | RESP | 10May2022 | |
1001 | No criteria defined for parameter | RESP | 26May2022 | |
1001 | No criteria defined for parameter | RESP | 01Jun2022 | |
1001 | No criteria defined for parameter | TEMP | 20Apr2022 | |
1001 | No criteria defined for parameter | TEMP | 10May2022 | |
1001 | No criteria defined for parameter | TEMP | 26May2022 | |
1001 | No criteria defined for parameter | TEMP | 01Jun2022 | |
1001 | No criteria defined for parameter | WEIGHT | 20Apr2022 | |
1001 | No criteria defined for parameter | WEIGHT | 10May2022 | |
1001 | No criteria defined for parameter | WEIGHT | 01Jun2022 | |
1001 | No criteria defined for parameter | HEIGHT | 20Apr2022 | |
1001 | No criteria defined for parameter | BMI | 20Apr2022 |
Assuming the data set file is already grouped by USUBJID/PARAMCD, then:
data want;
do until (last.paramcd);
set have;
by usubjid paramcd notsorted;
if a1ind='High' or a2ind='Change high' then ANL03FL='Y';
end;
do until (last.paramcd);
set have;
by usubjid paramcd notsorted;
output;
end;
run;
Since your words talk about A2IND but that is not in your data set, I only answer the part about A1IND.
proc sql;
create table want as select
*
,sum(a1nd='High')>0 as ANL03FL
from have
group by usubjid;
quit;
Also, since I prefer flag variables to be numeric 0 or 1, rather than "Y" or missing, I have programmed it to give you numeric 0s or 1s.
In the future, please do not provide data as screen captures, we cannot work with screen captures. In the future, please provide data as working SAS data step code, every single time, without us having to ask. Thank you.
Thanks for this but this but I need it to only populate for all records of the parameter that contains one record of "High". This seems to populate for all records for that subject.
Also that's absolutely fine regarding the screenshot I will populate data using datelines for your reference in the future. I appreciate the feedback
Just exclude records that don't have the flag = 1 in your next step.
Or modify the SQL code. As I said, we need data as SAS data step code and not as screen captures to write anything but the simplest code.
@smackerz1988 wrote:
Thanks for this but this but I need it to only populate for all records of the parameter that contains one record of "High". This seems to populate for all records for that subject.
Add the variable specifying the parameter (be it PARCAT1N or PARAMCD) to the GROUP BY clause:
group by usubjid, paramcd
Assuming the data set file is already grouped by USUBJID/PARAMCD, then:
data want;
do until (last.paramcd);
set have;
by usubjid paramcd notsorted;
if a1ind='High' or a2ind='Change high' then ANL03FL='Y';
end;
do until (last.paramcd);
set have;
by usubjid paramcd notsorted;
output;
end;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.