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

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

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;
Ranjeeta
Pyrite | Level 9
Thankyou !!
Ranjeeta
Pyrite | Level 9

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 

 

ballardw
Super User

@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.

novinosrin
Tourmaline | Level 20

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

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
  • 618 views
  • 2 likes
  • 3 in conversation