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

I'm trying to bring in two types of data:

1)   only those ids with suff codes in the primary position (dxSeqNo=1) ; 

OR

2) those with suff codes in the primary position AND those with rel code(s) in the secondary or greater position (dxSeqNo >1).

 

I have the below in SAS but it doesnt seem to be bringing it what I'm trying to ask for:

data dxsuffrel;
set acute_dx;
/*brings in sufficient in primary dx*/
if ((compress(icd,".") in (&asthma_suff, &cad_suff, &chf_suff, &copd_suff, &diab_suff, &htn_suff) and dxseqno=1)) OR 

/*brings in related in primary dx AND AT LEAST ONE sufficient code in additional dx*/
((compress(icd,".") in (&ASTHMA_REL, &CAD_REL, &CHF_REL, &COPD_REL, &DIAB_REL, &HTN_REL) AND dxSeqNo = 1)) AND 
((compress(icd,".") in (&ASTHMA_SUFF, &CAD_SUFF, &CHF_SUFF, &COPD_SUFF, &DIAB_SUFF, &HTN_SUFF) AND dxSeqNo > 1));
run;
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You probably have matching parentheses otherwise you would get an error in the log and no output data set.

 

So you need to add parentheses such that both parts of the OR condition are enclosed in parentheses.

--
Paige Miller

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

We don't know what your code is doing since we can't see (a portion of) your data and we don't have your macro variables; and we don't know what output you are getting that isn't correct.

 

So we would need ALL of that information in order to be specific.

 

However, one thing you might want to consider is that in your IF statement (which simplified looks like this)

 

if condition1 or condition2 and condition 3;

 

This is evaluated as 

 

if condition1 or (condition2 and condition 3);

and not as 

 

if (condition1 or condition2) and condition 3;

If you want this last IF statement you need to add proper parentheses.


And if that's not the problem then we need to see all the information I requested above.

--
Paige Miller
bhca60
Quartz | Level 8
yes its a parentheses issue. Thats where I'm confused.
PaigeMiller
Diamond | Level 26

@bhca60 wrote:
yes its a parentheses issue. Thats where I'm confused.

There's not enough information here for me to understand the problem.

--
Paige Miller
bhca60
Quartz | Level 8
I want this to be the outcome:
if (condition1 or condition2) and condition 3;
do i have too many parentheses or too little?
PaigeMiller
Diamond | Level 26

You probably have matching parentheses otherwise you would get an error in the log and no output data set.

 

So you need to add parentheses such that both parts of the OR condition are enclosed in parentheses.

--
Paige Miller
Tom
Super User Tom
Super User

@bhca60 wrote:
I want this to be the outcome:
if (condition1 or condition2) and condition 3;
do i have too many parentheses or too little?

Yes. Both.

You are running this:

if ((  compress(icd,".") in (&asthma_suff, &cad_suff, &chf_suff, &copd_suff, &diab_suff, &htn_suff)
       and dxseqno=1
   ))
OR 
   ((  compress(icd,".") in (&ASTHMA_REL, &CAD_REL, &CHF_REL, &COPD_REL, &DIAB_REL, &HTN_REL)
       AND dxSeqNo = 1
   ))
AND 
   ((  compress(icd,".") in (&ASTHMA_SUFF, &CAD_SUFF, &CHF_SUFF, &COPD_SUFF, &DIAB_SUFF, &HTN_SUFF)
       AND dxSeqNo > 1
   ))
;

So you don't need those doubled parentheses.  

But you do need to add a set to group the two OR conditions together.

if (
    (  compress(icd,".") in (&asthma_suff, &cad_suff, &chf_suff, &copd_suff, &diab_suff, &htn_suff)
       and dxseqno=1
    )
   OR 
    (  compress(icd,".") in (&ASTHMA_REL, &CAD_REL, &CHF_REL, &COPD_REL, &DIAB_REL, &HTN_REL)
       AND dxSeqNo = 1
    )
   )
AND 
   (  compress(icd,".") in (&ASTHMA_SUFF, &CAD_SUFF, &CHF_SUFF, &COPD_SUFF, &DIAB_SUFF, &HTN_SUFF)
       AND dxSeqNo > 1
   )
;

But that first test and the last test cannot both be true since DXSEQNO cannot be both 1 and greater than 1 at the same time. So perhaps you meant to do this instead?

if (  compress(icd,".") in (&ASTHMA_REL, &CAD_REL, &CHF_REL, &COPD_REL, &DIAB_REL, &HTN_REL)
       AND dxSeqNo = 1
   )
OR
   (  compress(icd,".") in (&ASTHMA_SUFF, &CAD_SUFF, &CHF_SUFF, &COPD_SUFF, &DIAB_SUFF, &HTN_SUFF)
       AND dxSeqNo > 1
   )
;

 

 

bhca60
Quartz | Level 8

I did the below and it brought way more data (I need the second condiiton to meet two conditions (related codes in primary position which is dxseqno=1 AND sufficient codes in secondary or greater position which is dxseqno>1 whereas the first condition is only looking for related codes in primary position only which is dxseqno=1):

data dxsuffrel;
set acute_dx;
/*brings in sufficient in primary dx*/
if ((icd in &asthma_suff and dxseqno=1) OR (icd in &cad_suff and dxseqno=1) OR (icd in &chf_suff and dxseqno=1) OR (icd in &copd_suff and dxseqno=1) OR 
(icd in &diab_suff and dxseqno=1) OR (icd in &htn_suff and dxseqno=1)) OR 

/*brings in related in primary dx AND AT LEAST ONE sufficient code in additional dx*/
((icd in &ASTHMA_REL and dxSeqNo = 1) OR (icd in &CAD_REL and dxSeqNo = 1) OR (icd in &CHF_REL and dxSeqNo = 1) OR (icd in &COPD_REL and dxSeqNo = 1) OR 
(icd in &DIAB_REL and dxSeqNo = 1)
OR (icd in &HTN_REL AND dxSeqNo = 1) AND 
(icd in &ASTHMA_SUFF and dxSeqNo>1) OR (icd in &CAD_SUFF and dxSeqNo>1) OR (icd in &CHF_SUFF and dxSeqNo>1) OR (icd in &COPD_SUFF and dxSeqNo>1) OR
(icd in &DIAB_SUFF and dxSeqNo>1) OR
(icd in &HTN_SUFF AND dxSeqNo > 1));
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 7 replies
  • 704 views
  • 0 likes
  • 3 in conversation