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?
please help!
Thanks.
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?
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:
PROC SQL;
UPDATE WORK.DATASET
SET telno = '0' || telno
WHERE state IN ('state1','state2');
QUIT;
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.
Hi audioa84, i think concatenation (||) requires character operands and zcta is a numeric variable so it could updated with a numeric expression only...
Thanks...
No problem, but I think you replied on the wrong thread. There is no mention of zcta on this thread.
Ya, i am sorry was working with two datasets together. but 'telno' is numeric so we can apply same logic...Thanks
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.
hi guys this onw worked
proc sql;
create table want as
select
state,
telno,
cats(case when state in ('s1','s2','s3') then '0' end, telno) as telnoChr
from
have;
quit;
Hello Guys,
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.
Thanks,
data have;
do var='9945','99','0954';
output;
end;
run;
data want;
set have;
var=ifc(length(var)=2,'0'||var,var);
run;
Haikuo
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.