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.
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
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
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.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.