BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

2 REPLIES 2
ballardw
Super User

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.

ChrisNZ
Tourmaline | Level 20

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.

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 872 views
  • 7 likes
  • 3 in conversation