BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TurnTheBacon
Fluorite | Level 6

If I have the number "15748645879", and want to add a space after the 6th number so that it becomes "157486 45879", how do I accomplish this in a DI Studio transformation expression (or format)?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
RichardinOz
Quartz | Level 8

Please clarify.  Is your starting value a numeric variable or a string?  If a numeric, are you wanting an output string in the format you describe?  (If so you will need a PICTURE format.)  But if your starting point is already a string and you need to insert a space you could achieve this with the SUBSTR() function.  Note that in the latter case the string length will have increased so your variable needs to be long enough to hold the extra space character.

Richard in Oz

View solution in original post

3 REPLIES 3
RichardinOz
Quartz | Level 8

Please clarify.  Is your starting value a numeric variable or a string?  If a numeric, are you wanting an output string in the format you describe?  (If so you will need a PICTURE format.)  But if your starting point is already a string and you need to insert a space you could achieve this with the SUBSTR() function.  Note that in the latter case the string length will have increased so your variable needs to be long enough to hold the extra space character.

Richard in Oz

TurnTheBacon
Fluorite | Level 6

Thanks. The variable is already a character, and it has a decent length, but I can't make SUBSTR do what I'd like. Any advice on this?

EDIT: Nevermind, got it, thanks again.

RichardinOz
Quartz | Level 8

     value = substr(value, 1, 6) || ' ' || substr(value, 7, 5) ;

should work if you want to put the result back into the same variable and you have the room.  If not, show me the log!!

Richard in Oz

data _null_ ;

    length value $12 ;

    value = "15748645879" ;

    value = substr(value, 1, 6) || ' ' || substr(value, 7, 5) ;

    Put value= ;

run ;

value=157486 45879

Message was edited by: Richard in Oz - added code to demonstrate

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 1306 views
  • 0 likes
  • 2 in conversation