Hello Communitie,
I am trying to validate a group of variables from two rows in same dataset, and if any of them doesn't match then abort/stop sas program. I tried something like this but doesn't seems to evaluate correctly.
data nextvar_compare;
nextvar=_n_+1;
set reporte end=last;
if not last
then set reporte(keep=nvar num_character num_numeric rename=(nvar=next_nvar num_character=next_num_character num_numeric=next_num_numeric)) point=nextvar;
else call missing(next_nvar, next_num_character, next_num_numeric);
run;
data _null_;
set nextvar_compare;
if nvar=next_nvar and num_character=next_num_character and num_numeric=next_num_numeric then
call symput("ValidaDS",0);
else;
call symput("ValidaDS",1);
run;
In a sas macro I would like to take ValidaDS value, if 1, then stop/abort, but always have a 1 even when the variables to compare have the same values
Can anyone advice or have a better way to do this?
Not sure I follow what you are trying to test, but I suspect the issue is your ELSE statement.
If you want to set a macro variable if some condition is EVER true then first set the macro variable to a default value and then set it to the opposite value when the condition is met.
Something like:
%let valid=1;
data _null_;
.....
if (... some condition...) then call symputx('valid','0');
run;
You can then use &VALID to control future steps.
Not sure I follow what you are trying to test, but I suspect the issue is your ELSE statement.
If you want to set a macro variable if some condition is EVER true then first set the macro variable to a default value and then set it to the opposite value when the condition is met.
Something like:
%let valid=1;
data _null_;
.....
if (... some condition...) then call symputx('valid','0');
run;
You can then use &VALID to control future steps.
Thank you @Tom. I've already did the variable initialization as you suggested and didn't work. However you point to where my problem is, the else sentence had an ";" at the end that was not necessary. I removed it and now it is evaluating correctly the if-then-else sentence.
Regards.
@Kal_ETL wrote:
Thank you @Tom. I've already did the variable initialization as you suggested and didn't work. However you point to where my problem is, the else sentence had an ";" at the end that was not necessary. I removed it and now it is evaluating correctly the if-then-else sentence.
Regards.
So now the macro variable will reflect the result of IF/THEN/ELSE test for only the LAST observation in the dataset.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.