05-19-2017 01:18 PM
i need some insight please!
what im trying to do is, read a column that needs to be seperated.
the column reads 3456789999
what i need to do is pad the first column
so i would split it in two clumns instr(columnA,4,7) to get 6789999
the 2nd column would need to be 0345 as the column needs to be 4 bytes.
and i want to concatenate the result 0345-6789999
05-19-2017 01:32 PM
Here is one way:
data have; input columna; cards; 3456789999 ; data want; set have; columnb=substr(strip(put(columna,best32.)),4); columnc=substr(put(columna,z11.),1,3); columnd=catx('-',columnc,columnb); run;
Art, CEO, AnalystFinder.com
05-19-2017 01:37 PM
You can use the Z format to make an 11 character string with leading zeros and then add the hyphen.
Or you could create a picture format. With the picture format you could leave the variable as numeric if you wanted.
proc format ; picture id low-high='9999-9999999' other=' '; run; data text ; length x1 x2 8 c1 c2 $12; x1=3456789999 ; x2=x1; format x1 z11. x2 id. ; c1=put(x1,Z11.); c1=catx('-',substr(c1,1,4),substr(c1,5)); c2=put(x1,id.); put (_all_) (=/); run;