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

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  

 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

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;
--------------------------
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

--------------------------

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
smackerz1988
Pyrite | Level 9

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

PaigeMiller
Diamond | Level 26

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.

 

--
Paige Miller
FreelanceReinh
Jade | Level 19

@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

 

mkeintz
PROC Star

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;
--------------------------
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

--------------------------

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 983 views
  • 3 likes
  • 4 in conversation