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

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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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