data test ;
set CR_CATHD;
where (Cath_SSPCIIND = 'Y' or Cath_ScheduledPCIIND = 'Y' or Cath_StagedPCIIND = 'Y')and FYEAR =2016 and RemovalReasonCD = 'PS' and AcceptanceHCPNumber=1302 ;
run;
Hello Can someone advise How I would write the step abve or if the step above is correct in order to achieve the following:
I want the count of cases where either of the conditions in the parentheses is Y and the conditions outside the parentheses are satisfied.
Ok, I am basically not filtering. I am basically counting the number of cases that satisfy the condition.
Please do take a look at the count.
Well , I think this should help you better as you really seem to want filtered records
data test ;
set CR_CATHD;
array t(*) Cath_SSPCIIND Cath_ScheduledPCIIND Cath_StagedPCIIND;
if 'Y' in t and FYEAR =2016 and RemovalReasonCD = 'PS' and AcceptanceHCPNumber=1302;
run;
Thats a subsetting if
Initially I assumed you wanted a count
data test ;
set CR_CATHD;
array t(*) Cath_SSPCIIND Cath_ScheduledPCIIND Cath_StagedPCIIND;
if 'Y' in t and FYEAR =2016 and RemovalReasonCD = 'PS' and AcceptanceHCPNumber=1302
then count+1;
run;
data test ;
285 set CR_CATHD;
286 array t(3) Cath_SSPCIIND Cath_ScheduledPCIIND Cath_StagedPCIIND;
287 if 'Y' in t and FYEAR =2016 and RemovalReasonCD = 'PS' and AcceptanceHCPNumber=953
288 then count+1;
289 run;
NOTE: There were 433888 observations read from the data set WORK.CR_CATHD.
NOTE: The data set WORK.TEST has 433888 observations and 241 variables.
NOTE: DATA statement used (Total process time):
real time 5.42 seconds
cpu time 1.29 seconds
What could be the reason that none of the filters are getting applied e.g.. FYear =2016 or
@Ranjeeta wrote:
data test ;
285 set CR_CATHD;
286 array t(3) Cath_SSPCIIND Cath_ScheduledPCIIND Cath_StagedPCIIND;
287 if 'Y' in t and FYEAR =2016 and RemovalReasonCD = 'PS' and AcceptanceHCPNumber=953
288 then count+1;
289 run;NOTE: There were 433888 observations read from the data set WORK.CR_CATHD.
NOTE: The data set WORK.TEST has 433888 observations and 241 variables.
NOTE: DATA statement used (Total process time):
real time 5.42 seconds
cpu time 1.29 seconds
What could be the reason that none of the filters are getting applied e.g.. FYear =2016 or
What makes you think none of the filters are applied?
The example here does not have any OR comparisons so the only values kept are the ones where all of the values match the IF condition. Though 'Y' in t is problematic. The SAS IN operator requires a fixed list of values. if you want to search a string value for Y anywhere in a variable the correct approach would be: if index(t,'Y') > 0. The index function returns the position number of the found value in the string variable or returns 0 if not found.
Ok, I am basically not filtering. I am basically counting the number of cases that satisfy the condition.
Please do take a look at the count.
Well , I think this should help you better as you really seem to want filtered records
data test ;
set CR_CATHD;
array t(*) Cath_SSPCIIND Cath_ScheduledPCIIND Cath_StagedPCIIND;
if 'Y' in t and FYEAR =2016 and RemovalReasonCD = 'PS' and AcceptanceHCPNumber=1302;
run;
Thats a subsetting if
Initially I assumed you wanted a count
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.