🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 06-03-2019 11:45 PM
(1167 views)
Hi team,
I have a dataset with a variable path, I need to extract the path till last but one and save it as new variable. Example:
Path;
/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
What I want is:
Path_1;
/c:/user/new/path1/path2/path3/path4/
/c:/user/old/new/path1/path2/path3/path4/
/c:/user/new/path5/path2/path3/path4/
/c:/user/old/new/path5/path2/path3/path4/
Regards,
GK
I have a dataset with a variable path, I need to extract the path till last but one and save it as new variable. Example:
Path;
/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
What I want is:
Path_1;
/c:/user/new/path1/path2/path3/path4/
/c:/user/old/new/path1/path2/path3/path4/
/c:/user/new/path5/path2/path3/path4/
/c:/user/old/new/path5/path2/path3/path4/
Regards,
GK
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;