BookmarkSubscribeRSS Feed
Jose7
Obsidian | Level 7

Hi experts,

I want to compare a hash value between some days and obtain a new table(s) with the results, just to known where the data has changed. The Second table has a day plus than the first table to make de evaluation and see if the next day has a different value. i'm not sure if i can do something like this :

 

%macro sqlloop(start,end);
PROC SQL;
DATE_FROM = '05MAY2019'D;
%DO ADD=&start. %TO &end.;
DATE_PLUS1=intnx('DAY',&DATE_FROM,1);
CREATE TABLE NewTable&ADD. as
SELECT t1.date, t1.account, t1.val_hash FROM table1 t1, table2 t2
WHERE t1.date = "&DATE_FROM"D AND t2.date = "&DATE_PLUS1"D
AND t1.account = t2.account
AND t1.VAL_HASH <> t2.VAL_HASH;
DATE_FROM=intnx('DAY',&DATE_FROM,1);
%END;
QUIT;
%mend;

%sqlloop(start=1, end=10)

 

table2 is a replicate of table1, just to make the comparisson between dates.
The val_hash column contains the data that i need to evaluate if it has changed.

1 REPLY 1
mkeintz
PROC Star

I strongly suggest you make working code without using it in a macro - i.e. make a single iteration of your loop that works.  Fill in constant values for a single iteration and debug it.

 

At the moment, if you removed all the macro-related parameters and variables, you would still have code that would generate error messages.  For instance you have:

 

PROC SQL;
    DATE_FROM = '05MAY2019'D;
    /* ... other code here ... */
QUIT;

 

 

Run this and you'll see that it fails.   

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1 reply
  • 740 views
  • 4 likes
  • 2 in conversation