BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PSIOT
SAS Employee

Hi,

I need to compare two macro variables containig string in macro program but it doesn't work.

Please see my code :

%if &currentdateFile = &LastDateFileToImport %then %do;

It seems that this condition is always true.

Where is my mistake?

Thanks a lot for your help

1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

What do those macro variables resolve to?  I can tell nothing from that snippet.

To test macro variable and such like:

options mlogic mprint symbolgen;

 

Put that before your program and you will see in the log all the information you need, its likely to be a spaces issue, or casing or something similar.

 

To note, you don't need to do the process that way at all.  If you show your code, then can advise, but if its text files, you can do in one datastep, and if Excel files or something, a dir list and datastep to generate a proc import for each dir would be simpler:

file mytemp pipe 'dir "c:\some\where\*.xlsx" /b';

data _null_;
  length bf $2000;
  infile mytemp dlm="¬";
  input bf $;
  call execute('proc import datafile="c:\some\where\'||strip(bf)||'" out=mydata'||strip(put(_n_,best.))||'; run;');
run;
  

This does a dir - then generates a proc import for each file in that dir, out is set as mydataX, where X is the row number.  You can modify as per your data.

Kurt_Bremser
Super User

It also may be that the macro is used in a way that makes it appear as if the condition is always true.

To determine that, you would need to post the whole macro code and the Base SAS code where it is used.

PSIOT
SAS Employee

Thank you for your help.

The answer is  %if "&currentdateFile" = "&LastDateFileToImport"  %then  %do;

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
  • 4 replies
  • 14581 views
  • 4 likes
  • 3 in conversation