04-26-2018 11:07 PM
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:
Basically i want to remove all the words after the last '\'. Can someone please help me to get the desired output? Thanks.
04-26-2018 11:53 PM
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
04-27-2018 04:05 AM
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.
Need further help from the community? Please ask a new question.