Hi,
data have;
input path $50.;
datalines;
/c:/user/new/path1/path2/path3/path4/cjx.sas
/c:/user/old/new/path1/path2/path3/path4/cjx.sas
/c:/user/new/path5/path2/path3/path4/cjx.sas
/c:/user/old/new/path5/path2/path3/path4/cjx.sas
;
run;
data want;
set have;
new_path= Tranwrd(path,'cjx.sas',"");
run;
Regards,
Anushree
Would this work:
data want;
FilePath = "/c:/user/new/path1/path2/path3/path4/cjx.sas";
Folder = substr(FilePath,1,length(FilePath)-length(scan(FilePath,-1,"/")));
run;
Or by using substr and findc:
data have_want;
length path directory $ 200;
input path;
directory = substr(path, 1, findc(path, '/', 'b'));
datalines;
/c:/user/new/path1/path2/path3/path4/cjx.sas
/c:/user/old/new/path1/path2/path3/path4/cjx.sas
/c:/user/new/path5/path2/path3/path4/cjx.sas
/c:/user/old/new/path5/path2/path3/path4/cjx.sas
;
run;
Hi,
data have;
input path $50.;
datalines;
/c:/user/new/path1/path2/path3/path4/cjx.sas
/c:/user/old/new/path1/path2/path3/path4/cjx.sas
/c:/user/new/path5/path2/path3/path4/cjx.sas
/c:/user/old/new/path5/path2/path3/path4/cjx.sas
;
run;
data want;
set have;
new_path= Tranwrd(path,'cjx.sas',"");
run;
Regards,
Anushree
data have_want;
length path directory $ 200;
input path;
directory = prxchange('s/[^\/]+$//',1,strip(path));
datalines;
/c:/user/new/path1/path2/path3/path4/cjx.sas
/c:/user/old/new/path1/path2/path3/path4/cjx.sas
/c:/user/new/path5/path2/path3/path4/cjx.sas
/c:/user/old/new/path5/path2/path3/path4/cjx.sas
;
run;
proc print;run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.