- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please help in validating this code. In 9.4 I am not able to get correct value of EXCLUDE in the output.
Seems like there is some error around 'and not missing'.
data test;
set test1;
array hra_ (*) &hras.;
array d_(&ct.);
do i=1 to &ct.;
if (((max(of hra_ (*)) = . and min(of hra_(*)) = .)
and not missing(HRA_previous_yr))
or ((max(of hra_ (*)) = min(of hra_ (*))) and
not missing(HRA_previous_yr) and (HRA_previous_yr) = max((of hra_ (*))))
and intck('day', HRA_previous_yr, disenrollment_date) < 365
then do; EXCLUDE = "XYZ";
END;
END;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You should provide some test data and the log of your run.
What do you mean by EXCLUDE = "XYZ"; ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hey
I am getting the output, but the value in the Variable EXCLUDE is not coming as "XYZ". Suspecting that the IF condition has some error.
EXCLUDE = "XYZ" is a command given to create variable EXCLUDE with value as "XYZ".
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/
Please also post your log. We can't tell what's going on without your log.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
In addition to @Shmuel's suggestions, you should format your code by using the run symbol in the body tab in your post.
data test;
set test1;
array hra_ (*) &hras.;
array d_(&ct.);
do i=1 to &ct.;
if (((max(of hra_ (*)) = . and min(of hra_(*)) = .)
and not missing(HRA_previous_yr))
or ((max(of hra_ (*)) = min(of hra_ (*))) and
not missing(HRA_previous_yr) and (HRA_previous_yr) = max((of hra_ (*))))
and intck('day', HRA_previous_yr, disenrollment_date) < 365
then do; EXCLUDE = "XYZ";
END;
END;
run;
Try to create some normal programming syntax pattern so that your code is readable. Indentation is important to break up various statements.
Where are your macro variables coming from (&ct., &hras.)? That's another question in itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for spacing the code. Here is the Log
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
First thing: What the heck is that do i= loop in there for? Your shown code would loop over the exact same values however many times the value of &Ct may be. One almost might guess that once upon a time this iterated over the values of one of the arrays testing each value but this code doesn't. You aren't referencing either of the arrays using i as an index.
Hint: If an array of numeric values returns missing, as in
max(of hra_ (*)) = .
the min will ALWAYS be missing as the only way the Max and Min functions return missing is when all values are missing.
So the bit of
and min(of hra_(*)) = .
is not needed and adds additional () that aren't actually needed after removing the min. Alternate code could also be to test if all values are missing.
nmiss(of hra_(*)) = dim(hra_a)
The bit of
max(of hra_ (*)) = min(of hra_ (*))
Could be replaced with
Range( of hra_(*))=0
Range is largest non-missing minus smallest non-missing. So when the max and min are the same the range is 0.
Note: You may also need to consider Leap years some where if that is why you are hard coding 365.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If the code is unchanged and it used to work and now it doesn't then the DATA has changed. Either the input dataset or the two input macro variables.
The code is confusing with extra parentheses that are not needed and it looks like you are missing some parentheses that are probably needed. It looks like you have a logical expression in the form
A or B and C
Did you mean
(A or B) and C
or did you mean
A or (B and C)
Please explain in words what you condition is trying to detect.
Note to test if all of the values are missing just use the N( ) function. If N(of HRA_[*]) is zero then all of the variables are missing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Condition 1: (max(HRA) = missing and min(HRA) = missing) and HRA_prev_yr is not missing
OR
Condition 2: max(hra) = min(HRA) and HRA_prev_yr is not missing and HRA_prev_yr = max(HRA)
and intck('day',hra_prev_yr,disenrollment_date) <365
So it is A OR B.
Note: HRA here is macros with arrays ranging from 1 to 41 and is in date format.