03-27-2013 12:22 PM
Hi Guys, i have two variable in dataset named 'telno' and 'state', couple of state required zero '0' in front of 'telno' variable. if i wants to add zero '0' for couple of states only, how can i do that?
03-27-2013 12:41 PM
if state in ('NJ','NY'....) then phone=' 0-' || phone;
Sorry i am new to SAS but this is what i'd think of first
I bet phone is a char variable and you specified the length at the top of your code?
03-27-2013 02:25 PM
Frank, can you confirm if 'telno' is a char (text value)? If it is, Tal has the right idea. You could do an update using PROC SQL by doing the following:
Open a new SAS Program by right clicking the blank area on a process flow, select new, select Program. Then enter the following code:
SET telno = '0' || telno
WHERE state IN ('state1','state2');
Just change WORK.DATASET to the name of your data set and change the states and you should be able to run the code. There are other ways to do this as well, I just chose the first one to come to mind.
03-27-2013 03:21 PM
Hi audioa84, i think concatenation (||) requires character operands and zcta is a numeric variable so it could updated with a numeric expression only...
03-28-2013 04:05 AM
If telno is numeric, you can't store the telno with leading 0, that's how SAS (and most other SW) does.
If you like, you could apply the Zn. format to your column, but you can't do that dependent on values in other columns.
So I guess you need to create a new telno char column to fulfill your requirement.
03-29-2013 10:12 AM
hi guys this onw worked
create table want as
cats(case when state in ('s1','s2','s3') then '0' end, telno) as telnoChr
04-04-2013 09:41 AM
I have a character variable which has values like (9945,99,0954) and I want to make variable values like (9945,099,0954).
I want to insert a leading zero if my character variable is of length two.
I am wondering if you can help.