Imagine that you have a folder with the following reports:
Commissions GW 0413 Ohio
Commissions GW 0413 Indiana
Commissions GW 0413 Minnesota
Commissions GW 0413 Illinois
Commissions GW 0413 Pennsylvania
Commissions GW 0413 Colorado
You want SAS to read the file names starting from "GW", and you want to turn the spaces into underscores. So, when read into SAS, the strings should look like this:
reportname
GW_0413_Ohio
GW_0413_Indiana
GW_0413_Minnesota
GW_0413_Illinois
GW_0413_Pennsylvania
GW_0413_Colorado
I think this can be done by means of the SCAN function, but I can't seem to make it work. I'd appreciate any advice.
Thanks for your time.
A combination of call scan/indexw and translate should do the trick.
Hi.
Maybe this could work:
data want;
set have;
new_string = translate(trim(prxchange("s/.*Commissions //", -1, string)), "_", "");
run;
prxchange : will replace/change everything up to (including) the word Commissions with a blank space;
trim : will remove the trailing blanks (so you don't attach an underscore at the end of the string;
translate : will replace any blanks with underscore.
Good luck!
Anca.
Thanks, I was able to do it using substr and translate.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.