Hello,
I need to test if &csvfile containt the name of a file or no suc file . Then if there is a csv file then import the data into a sas data set . Otherwise, put there is no csv file to import into a sas dataset.
%macro test;
%let csvfile=*.csv: No such file or directory;
%let csvfile=Master_list_20241031.csv;
%if %sysfunc(find(&csvfile,'No such file')) = 0 %then
%do;
%put "there is a none empty csv file to import into a sas dataset";
%end;
%else
%do;
%put "There is no csv file to import into a SAS dataset";
%end;
%mend test;
%test;
If I select the first csvfile, I am expecting to get There is no csv file to import into a SAS dataset and if I use the second value I expect to get
there is a none empty csv file to import into a sas dataset
It is not working properly What's wrong
When you add quotes to values to search for in the MACRO language then if the searched string doesn't have the quotes you don't get a match.
Run this:
%let csvfile=*.csv: No such file or directory; %put %sysfunc(find(&csvfile,'No such file')); %put %sysfunc(find(&csvfile,No such file));
The 8 from the second %put shows that the text is found.
When you add quotes to values to search for in the MACRO language then if the searched string doesn't have the quotes you don't get a match.
Run this:
%let csvfile=*.csv: No such file or directory; %put %sysfunc(find(&csvfile,'No such file')); %put %sysfunc(find(&csvfile,No such file));
The 8 from the second %put shows that the text is found.
Every value in the macro language is a string.
So you should not use quotes for the variable values, unless of course the value contains quotes.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.