BookmarkSubscribeRSS Feed
Ranjeeta
Pyrite | Level 9

data Non_QBP_PBF_STROKE (keep = HEM_NONQBP ISC_NONQBP HEM_QBP ISC_QBP INDEX_ACUTE);

set pbf_stroke;

If  sum(of HEM_NONQBP ISC_NONQBP) =1 and INDEX_ACUTE=1 and sum(of HEM_QBP ISC_QBP)=0;

run;

 

How would I write the above step correctly

 

I want to get the count of all cases where either HEM_NONQBP or ISC_NONQBP=1 and index-acute=1 and HEM_QBP or ISC_QBP should be 0

 

Thanks

5 REPLIES 5
novinosrin
Tourmaline | Level 20
If  sum(HEM_NONQBP, ISC_NONQBP) >=1 and INDEX_ACUTE=1 and  (HEM_QBP=0 or ISC_QBP=0);
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @Ranjeeta 

 

There is a difference between your logic and the description of what you want.

 

Your logic (with @novinosrin 's corrections)  says that HEM_QBP  and ISC_QBP should both be 0, but your description says that either  HEM_QBP or ISC_QBP should be 0.

 

 

ballardw
Super User

@Ranjeeta wrote:

data Non_QBP_PBF_STROKE (keep = HEM_NONQBP ISC_NONQBP HEM_QBP ISC_QBP INDEX_ACUTE);

set pbf_stroke;

If  sum(of HEM_NONQBP ISC_NONQBP) =1 and INDEX_ACUTE=1 and sum(of HEM_QBP ISC_QBP)=0;

run;

 

How would I write the above step correctly

 

I want to get the count of all cases where either HEM_NONQBP or ISC_NONQBP=1 and index-acute=1 and HEM_QBP or ISC_QBP should be 0

 

Thanks


If  sum(of HEM_NONQBP ISC_NONQBP) =1 is FALSE when both of HEM_NONQBP  ISC_NONQBP are = 1.

If the variables are 0/1 coded perhaps you want

if max( of HEM_NONQBP ISC_NONQBP) =1)

 

similar sum(of HEM_QBP ISC_QBP)=0 is not true when either is 1 and the other 0. If the variables actually have more values than 0/1 you have a potential very large number of ways to the sum to be zero when neither of the variables is 0.

 

Here are all of the possible combinations of your variables if they are all coded 0/1. Indicate which of these are the ones you want to keep. Either mark the Result column with an x or provide the obs numbers.

        HEM_      ISC_     INDEX_
Obs    NONQBP    NONQBP     ACUTE    HEM_QBP    ISC_QBP    result

  1       0         0         0         0          0
  2       0         0         0         0          1
  3       0         0         0         1          0
  4       0         0         0         1          1
  5       0         0         1         0          0
  6       0         0         1         0          1
  7       0         0         1         1          0
  8       0         0         1         1          1
  9       0         1         0         0          0
 10       0         1         0         0          1
 11       0         1         0         1          0
 12       0         1         0         1          1
 13       0         1         1         0          0
 14       0         1         1         0          1
 15       0         1         1         1          0
 16       0         1         1         1          1
 17       1         0         0         0          0
 18       1         0         0         0          1
 19       1         0         0         1          0
 20       1         0         0         1          1
 21       1         0         1         0          0
 22       1         0         1         0          1
 23       1         0         1         1          0
 24       1         0         1         1          1
 25       1         1         0         0          0
 26       1         1         0         0          1
 27       1         1         0         1          0
 28       1         1         0         1          1
 29       1         1         1         0          0
 30       1         1         1         0          1
 31       1         1         1         1          0
 32       1         1         1         1          1

If the variables are coded other than 0/1 you'll have to provide example data as your problem using SUM with or instead of possibly MAX or MIN has a very large possible set of solutions.

Ranjeeta
Pyrite | Level 9
Thankyo for all your support I have a result i need nw will post an update and look at the proposed solution to learn more
Reeza
Super User

You can use the same filter condition in SQL or a WHERE statement if needed.

I assumed that hem_qbp = 1 and hem_nonqbp are complementatry, when one of the variables is a 1, the other will be 0. It doesn't really matter if that's true though, the condition should work the same. Note that | is an OR operator and this works assuming your variables are all binary. If it's 1/2 then it may be different. 

 

*Fake data;
data have;
    call streaminit(100);

    do i=1 to 1000;
        hem_qbp=rand('bernoulli', 0.4);
        hem_nonqbp=not hem_qbp;
        isc_nonqbp=rand('bernoulli', 0.6);
        index_acute=rand('bernoulli', 0.1);
        isc_qbp=not isc_nonqbp;
        output;
    end;
run;

*filter based on conditions;
data want;
    set have;

    IF index_acute=1 and (hem_nonqbp | isc_nonqbp) and (hem_qbp | isc_qbp);
run;

@Ranjeeta wrote:

data Non_QBP_PBF_STROKE (keep = HEM_NONQBP ISC_NONQBP HEM_QBP ISC_QBP INDEX_ACUTE);

set pbf_stroke;

If  sum(of HEM_NONQBP ISC_NONQBP) =1 and INDEX_ACUTE=1 and sum(of HEM_QBP ISC_QBP)=0;

run;

 

How would I write the above step correctly

 

I want to get the count of all cases where either HEM_NONQBP or ISC_NONQBP=1 and index-acute=1 and HEM_QBP or ISC_QBP should be 0

 

Thanks


 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1097 views
  • 4 likes
  • 5 in conversation