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

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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