data t1;
length v1 $ 100;
input v1 $;
datalines;
G:/Data/CXV/PGMS/CTS_Test/Scripts/ScannedFiles1.txt
D:/Data/ABC/PGMS/CTS_Test/Scripts/ScannedFiles2.txt
E:/Data/XYZ/PGMS/CTS_Test/Scripts/ScannedFiles3.txt
C:/Data/DEF/PGMS/CTS_Test/Scripts/ScannedFiles4.txt
F:/Data/JFK/PGMS/CTS_Test/Scripts/ScannedFiles5.txt
;
run;
I need to extract only folder, not file (which is last ). Can you please help.
G:/Data/CXV/PGMS/CTS_Test/Scripts
D:/Data/ABC/PGMS/CTS_Test/Scripts
E:/Data/XYZ/PGMS/CTS_Test/Scripts
C:/Data/DEF/PGMS/CTS_Test/Scripts
F:/Data/JFK/PGMS/CTS_Test/Scripts
Thanks in Adavance.
data t1;
length v1 $ 100;
input v1 $;
want=prxchange('s/\/[^\/]+$//',1,strip(v1));
datalines;
G:/Data/CXV/PGMS/CTS_Test/Scripts/ScannedFiles1.txt
D:/Data/ABC/PGMS/CTS_Test/Scripts/ScannedFiles2.txt
E:/Data/XYZ/PGMS/CTS_Test/Scripts/ScannedFiles3.txt
C:/Data/DEF/PGMS/CTS_Test/Scripts/ScannedFiles4.txt
F:/Data/JFK/PGMS/CTS_Test/Scripts/ScannedFiles5.txt
;
run;
You can use substr function in SAS to extract sub-string from a string. You can set the start and end position to fetch sub string from variable v1.
Try this one:
data out;
set t1;
v1_new = substr(v1,1, 33);
run;
Addition to the above solution.
data want;
set t1;
v2= substr(v1, 1, length(v1) - length(scan(v1, -1, '/'))-1);
proc print; run;
This code works for dynamic path.
data want;
set t1;
where=find(v1,'/',-100);
folder_name=substr(v1,1,where-1);
drop where;
run;
@kumarsandip975 please do not use meaningless subject lines like "Programming Help", because virtually every thread can be "Programming Help". Please, from now on, make the subject line a brief description of the problem.
data t1;
length v1 $ 100;
input v1 $;
want=prxchange('s/\/[^\/]+$//',1,strip(v1));
datalines;
G:/Data/CXV/PGMS/CTS_Test/Scripts/ScannedFiles1.txt
D:/Data/ABC/PGMS/CTS_Test/Scripts/ScannedFiles2.txt
E:/Data/XYZ/PGMS/CTS_Test/Scripts/ScannedFiles3.txt
C:/Data/DEF/PGMS/CTS_Test/Scripts/ScannedFiles4.txt
F:/Data/JFK/PGMS/CTS_Test/Scripts/ScannedFiles5.txt
;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: