BookmarkSubscribeRSS Feed
krisraa
Quartz | Level 8

Hi

 

I have 2 data sets (Current and Prev month).

 

I need to compare the 2 datasets no. of observations and if the current month data set has more no. of records then I need to run or call a macro?

 

How do I achieve that?

 

 

6 REPLIES 6
ShiroAmada
Lapis Lazuli | Level 10

Try this....

 

proc sql noprint;
  select nobs into: curr from dictionary.tables
  where upcase(libname)="MYLIB" and upcase(memname)='MY_CURR';

  select nobs into: PREV from dictionary.tables
  where upcase(libname)="MYLIB" and upcase(memname)='MY_PREV';
QUIT;

%macro HasMore;
%if %eval(&prev<curr) %then %do;
  %MyMacro;
%end;

%mend

%HasMore;

Hope this helps.

ChrisNZ
Tourmaline | Level 20

Like this?

data _null_;
  if NOBS1 ne NOBS2 then call execute('%mymacro;');
  set TABLE1 nobs=NOBS1;
  set TABLE2 nobs=NOBS2;
  stop;
run;

Simple since there is no macro language, and fast since we don't use the dictionary.

 

krisraa
Quartz | Level 8

Thanks Chris it did the job for me....

 

Any specific reason why the if logic before reading the data sets?

SAS_inquisitive
Lapis Lazuli | Level 10

nobs are obtained during compile time so they can be used before SET statement.

ChrisNZ
Tourmaline | Level 20

If you put it after the SET statements and one of the data sets is empty, it will never be executed.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 6 replies
  • 1299 views
  • 6 likes
  • 5 in conversation