BookmarkSubscribeRSS Feed
JeremyCAdams
Calcite | Level 5

You could make the macro return a value if you really have to have it that way, but it's not great programming practice in SAS:

%MACRO checkForVars(var1,var2,var3);
    %let var1=%sysfunc(dequote(&var1));
    %let var2=%sysfunc(dequote(&var2));
    %let var3=%sysfunc(dequote(&var3));
    %let dsid=%sysfunc(open(&inDS));
    %let check=%sysfunc(varnum(&dsid,&var1));
    %if &check ^= 0 %then %do;
        %let check=%sysfunc(varnum(&dsid,&var2));
        %if &check ^= 0 %then %do;
            %let check=%sysfunc(varnum(&dsid,&var3));
            %let rc=%sysfunc(close(&dsid));
            %if &check ^= 0 %then %let out=Y;
            %end;
        %end;
        %else %do;
        %let rc=%sysfunc(close(&dsid));
        %let out=N;
        %end;
&out
%MEND checkForVars;
%let end_date_flg="%checkForVars('cdexpm','cdexpd','cdexpy')";

Notice the missing semicolon at the &out part of the macro. This will send the value of the variable out back to wherever the macro was called from. In this case, this macro sends back a value of "Y" or "N" to indicate whether one of the three variables passed to it exists in the dataset.

lacrefa
Calcite | Level 5

Dear

You can have a view using the "Hash Iterator Object" inside this document "http://support.sas.com/rnd/base/datastep/dot/iterator-getting-started.pdf"

This one use a comparison between date and you can adapte using index funtion. The small table can be used as hash table.

Regards

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
  • 16 replies
  • 2681 views
  • 6 likes
  • 9 in conversation