Hello,
Is there a way to eliminate the file extension.
%macro lastmodifiedfile2(path,string,MName);
/** Change the filename below to the following to run on UNIX **/
/** filename test pipe "ls &path -rt"; **/
/** Change the filename below to the following to run on Windows **/
/** filename test pipe "dir &path /od /t:w /b"; **/
/*filename test pipe "ls &path -rt";*/
/*filename test pipe "ls &path -rt|basename |grep &string.";*/
filename test pipe "ls &path -rt|grep &string. ";
data _null_;
infile test;
input;
call symputx("&Mname.",_infile_,'g');
run;
%put Last file to be modified in &path is: &Mname.;
%mend lastmodifiedfile2;
%lastmodifiedfile2(&soudest1.,&suffix1., FName1);
%put &Fname1.
&Fname1 is equal to pilote_2017_2021_validation_v004.mdf.0.0.0.spds9
Is there an extra command I can add to get only pilote_2017_2021_validation_v004
Regards,
Have you tried SCAN function in the call symputx?
Something like that:
%macro lastmodifiedfile2(path,string,MName);
/** Change the filename below to the following to run on UNIX **/
/** filename test pipe "ls &path -rt"; **/
/** Change the filename below to the following to run on Windows **/
/** filename test pipe "dir &path /od /t:w /b"; **/
/*filename test pipe "ls &path -rt";*/
/*filename test pipe "ls &path -rt|basename |grep &string.";*/
filename test pipe "ls &path -rt|grep &string. ";
data _null_;
infile test;
input;
call symputx("&Mname.",scan(_infile_,1,'.'),'g');
run;
%put Last file to be modified in &path is: &Mname.;
%mend lastmodifiedfile2;
%lastmodifiedfile2(&soudest1.,&suffix1., FName1);
Have you tried SCAN function in the call symputx?
Something like that:
%macro lastmodifiedfile2(path,string,MName);
/** Change the filename below to the following to run on UNIX **/
/** filename test pipe "ls &path -rt"; **/
/** Change the filename below to the following to run on Windows **/
/** filename test pipe "dir &path /od /t:w /b"; **/
/*filename test pipe "ls &path -rt";*/
/*filename test pipe "ls &path -rt|basename |grep &string.";*/
filename test pipe "ls &path -rt|grep &string. ";
data _null_;
infile test;
input;
call symputx("&Mname.",scan(_infile_,1,'.'),'g');
run;
%put Last file to be modified in &path is: &Mname.;
%mend lastmodifiedfile2;
%lastmodifiedfile2(&soudest1.,&suffix1., FName1);
I would rather use FINDC with "B", so I get the position of the last period; filenames might contain more than one period, and only the last is wanted to remove the extension.
call symputx("&Mname.",substr(_infile_,1,findc(_infile_,".","b")-1),"g");
And to only get the first filename returned by the external command, STOP at the end of the data step, so that only one iteration is performed.
Or add another command:
ls &path -rt|grep &string. |head -1
ls -rt gives you the files in reverse order of the modification time. grep filters out those files containing the string in the name, and head -1 filters the first line.
Adding l to the ls call (ls -lrt) displays (among other things) the modification time.
So you could read the results of the simple ls -lrt into a dataset, and inspect that.
"Learning UNIX" is so broad that it dwarfs "learning Shakespeare", by orders of magnitude.
Start with the basic utilities you will use:
ls
cd
cp
mv
rm
pwd
more (or its more modern brother less)
cat
echo
grep
find
head
tail
kill
Next, make yourself familar with the most widely used shell, bash, and how to write scripts in it.
Doing a google search for "command manual" will quickly lead you to resources for the command.
A good starting point will also be the the manufacturer's website, like this for IBM's AIX.
If, OTOH, you want to extract
pilote_2017_2021_validation_v004
from
pilote_2017_2021_validation_v004.mdf.0.0.0.spds9
then the SCAN method is valid.
Examples like this show how hard it can be to make a macro so flexible that it deals with all possible scenarios; in the end you end up doing more work on the macro than the discrete solutions would need.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.