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