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

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.

 

Kal_ETL_0-1656357619239.png

 


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

 

Kal_ETL_1-1656357757376.png

 

Can anyone advice or have a better way to do this?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

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.

Kal_ETL
Obsidian | Level 7

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.

Tom
Super User Tom
Super User

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

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1080 views
  • 0 likes
  • 2 in conversation