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);

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 5982 views
  • 5 likes
  • 5 in conversation