BookmarkSubscribeRSS Feed
TurnTheBacon
Fluorite | Level 6

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. Smiley Happy

3 REPLIES 3
LinusH
Tourmaline | Level 20

A combination of call scan/indexw and translate should do the trick.

Data never sleeps
AncaTilea
Pyrite | Level 9

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.

TurnTheBacon
Fluorite | Level 6

Thanks, I was able to do it using substr and translate. Smiley Happy

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to connect to databases in SAS Viya

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.

Discussion stats
  • 3 replies
  • 2027 views
  • 6 likes
  • 3 in conversation