what is the way to separate a string of digits (e.g. 1103) in 3 different column? I have a string of 4 digits. the first digit symbolize "attribute 1" the second "attribute 2" the last two the IDnumber.
This works, but only when I import the data as character.
When I have Numeric like;
var1 = substr(str, 1,1);
var2 = substr(str, 2,1);
var3 = substr(str, 3,2);
it doesn't work.
When I have used the digits as characters, then I can not convert it back in numeric. The procedure
informat var1 var2 best1. var3 best2.;
format var1 var2 best1. var3 best2.;
can't be interpret by sas.
If you'll need to convert it back in numeric you might want to use the input function. And just a curious about this, why convert it back to numeric after you have changed it into a character already? Will you be using the splitted digits for computations?
In order to parse a SAS numeric variable based on digit-position, you must use the SAS PUT function with the desired output FORMAT (second argument), such as Z4., in order to give you a formatted SAS variable/value to parse.
The easy way is to [pre]substr(put(x,z4.)...[/pre] but you can do it with arithmitic functions.
350 data _null_;
351 do s = 1103,1010,0330,0901,0001,9999,0000;
352 a = int(s/1e3);
353 b = int(mod(int(s/1e2),1e1));
354 c = int((s/1e2-int(s/1e2))*1e2);
355 put (_all_)(=);
357 format s z4. a b f1. c z2.;