Hello,
I have a macro variable something like below and i want to remove the string after the last '\'. and store the output in macro
%let path = D:\input\sas\files\today\chart_data*.sas7bdat;
Expected output is:
D:\input\sas\files\today\
Basically i want to remove all the words after the last '\'. Can someone please help me to get the desired output? Thanks.
%let path = D:\input\sas\files\today\chart_data*.sas7bdat;
%let want=%sysfunc(prxchange(s/[^\\\/]+$//,1,&path));
%put &want;
One easy and lazy way:
%let path = D:\input\sas\files\today\chart_data*.sas7bdat;
data _null_;
k="&path";
call scan(k, -1, position, length,'\');
substr(k,position,length)=' ';
call symputx('path',k);
run;
%put &path;
However, I challenge you to accomplish the same with %syscall with call scan in open code or rxchange
You could double reverse it:
data want; pth=reverse(scan(reverse("&path."),1,"\")); run;
Basically reverse the string, scna off the first block based on \ delimiter, then reverse the result.
%let path = D:\input\sas\files\today\chart_data*.sas7bdat;
%let want=%sysfunc(prxchange(s/[^\\\/]+$//,1,&path));
%put &want;
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.
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.