Hello SAS experts,
I have a string of characters that I need everything before '.csv' and I fail to get the whole thing
this is literally how they are naming the files and the file names can not be changed...
Valdoste T.C. 8-19.csv
Valdoste T.C Nov 2019.csv
Valdoste T.C. Sept 2019.csv
Valdoste T.C. December 2018.csv
I keep changing to '.' and '-' and to the 1,2,3 word but nothing is working. I new to sas so what seems like an easy fix has me going round and round. please assist.
code
data dirlist3 ;
set want;
Sheetname1=scan(name,2,'-');
run;
Sheetname1=tranwrd(name,'.csv','');
Try
want=substr(str,1,find(str,'.csv','i')-1);
If they all end in ".csv", then replace the last 4 characters with '' (null).
data have;
length name $50.;
name = 'Valdoste T.C. 8-19.csv';
output;
name = 'Valdoste T.C Nov 2019.csv';
output;
name = 'Valdoste T.C. Sept 2019.csv';
output;
name = 'Valdoste T.C. December 2018.csv';
output;
run;
data want;
set have;
substr(name,length(name)-3,4)='';
run;
Hi @unison You know what, At 5:36 PM my eyes are red and damn tired and I wanna get a can of beer, go home and crash. That simplicity in your solution has alerted me to go home and crash. Well thought out. Kudos!
Sheetname1=prxchange('s/\.csv//', 1, name);
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.