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;

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