08-05-2014 10:08 AM
I've a SAS variable which is numeric with the same length for all records and I need to modify with one leading zeros and it still be numeric for all records like below.
Please suggest me to achieve this task
08-05-2014 10:39 AM
I already seen the Zw. format but I'm not sure how it can be incorporated in SAS code as it is been often used with Input and Put function
08-05-2014 10:43 AM
Use Format for Proc Print and Put to create a String:
Format Phone Z11.;
08-14-2014 03:43 AM
I would prefer the Phone_Text-version which transforms the character to numeric over the Phone_Text2-version:
Input Phone $;
Phone_Text2=Repeat('0',10-Length(Phone))!!Phone; /* use a Macro-Variable instead of 10 */
08-14-2014 04:38 AM
thanks, but in the interest of time could you please tell me the significance of !! in the line Phone_Text2=Repeat('0',10-Length(Phone))!!Phone;
08-14-2014 04:56 AM
!! is a concatenating operator. I use it instead of vertical bars (||). The reason is, that my keyboard does not have a solid vertical bar, so I use either two broken vertical bars (¦¦) or two exclamation marks (!!).
08-14-2014 03:58 AM
Hope one of below options will do for you:
infile datalines truncover;
input @1 Phone_Char $11. @1 Phone_Num 11.;
format Phone_Num2 z11.;
08-05-2014 10:44 AM
You could apply it to the number variable, or you can create a new character variable and put the number into the Z format. Or you could apply the format in proc report etc.
format mobilenumber z11.;
08-14-2014 04:55 AM
Patrick has been nice enough to provide many examples of this. The !! means concatenate. What the code is doing is checking the existing length of Pone. Then if less than 10 create a string of 0's to pad out to 10 length and concatenate these to Phone.
Also, it does not matter if you input is character and you want character out, you can still do put(input()) as User24feb has stated: Phone_Text=Put(Input(Phone,Best11.),Z11.);
This converts the string to number, uses Z. format to padd it, then puts it back to character and assigns the character result back into your original character format. So you end up with the original variable with the data padded.