BookmarkSubscribeRSS Feed
lisa2002
Fluorite | Level 6

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;

5 REPLIES 5
PaigeMiller
Diamond | Level 26
Sheetname1=tranwrd(name,'.csv','');
--
Paige Miller
novinosrin
Tourmaline | Level 20

Try

 

want=substr(str,1,find(str,'.csv','i')-1);
unison
Lapis Lazuli | Level 10

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;
-unison
novinosrin
Tourmaline | Level 20

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!

ed_sas_member
Meteorite | Level 14
Sheetname1=prxchange('s/\.csv//', 1, name);

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 5035 views
  • 5 likes
  • 5 in conversation