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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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