Need to compare two sas MACRO VARIABLE containing string

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

Need to compare two sas MACRO VARIABLE containing string

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


Accepted Solutions
Solution
‎11-25-2016 08:55 AM
Esteemed Advisor
Posts: 6,723

Re: Need to compare two sas MACRO VARIABLE containing string

Do

%put currentdateFile="&currentdateFile";
%put LastDateFileToImport="&LastDateFileToImport";

immediately before your %if and then post the log of this.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎11-25-2016 08:55 AM
Esteemed Advisor
Posts: 6,723

Re: Need to compare two sas MACRO VARIABLE containing string

Do

%put currentdateFile="&currentdateFile";
%put LastDateFileToImport="&LastDateFileToImport";

immediately before your %if and then post the log of this.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Esteemed Advisor
Esteemed Advisor
Posts: 7,253

Re: Need to compare two sas MACRO VARIABLE containing string

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.

Esteemed Advisor
Posts: 6,723

Re: Need to compare two sas MACRO VARIABLE containing string

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 24

Re: Need to compare two sas MACRO VARIABLE containing string

Thank you for your help.

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 853 views
  • 0 likes
  • 3 in conversation