12-17-2016 05:25 AM
please provide the below mentioned
In a dataset there are two variables ,with one of the variable has parentheses around them. Combine these into a single numeric variable called " and remove the parentheses and add a leading zero
12-17-2016 06:23 AM
The question is misleading, as it is really not possible. There is no such thing as a numeric variable that contains a leading zero. If you know the length of a variable, you can print it with leading zeros but that's only the printing format. The variable itself does not contain any leading zeros.
TRANSLATE function handles this pretty easily but creates a character variable:
newvar = translate(oldvar, ' 0', ')(' );
12-17-2016 09:15 AM
12-17-2016 10:33 AM
As you haven't confirmed what the data looks like, will still have to guess:
set have; var1="(1234)"; var2=5555; result=input(cats(tranwrd(var1,"()"),put(var2,b
format result z9.; run;
This only displays the data using Zx. format to show the extra 0, as said above numeric values do not have the ability to hold preceeding zeroes.
12-17-2016 12:09 PM
So you will need to do more of the work here. There are too many pieces that could be defined one way or the other.
Regarding the inputs: Is NUMBER numeric or character? Most phone numbers look more like 555-2134 with a dash in the middle that means it is character. What is actually in your data? If there is a dash there originally, do you want it removed?
Regarding the output: There still is no such thing as a numeric variable that contains a leading zero. So what do you want? A list of digits in a file, where the first digit is a zero?
Give a specific example showing what one line of input looks like, and what the corresponding output should be.
12-17-2016 08:09 AM
A good idea is to post test data - in the form of a datastep - and what the output should look like. This is so that we - who don't know what you have/are doing - can try to understand the problem and the required outcome.
Your first variable will be character - numeric variables cannot have () in them. Is the second variable numeric or character - you see this is where the test data in the form of a datastep comes in.
Numeric values do not have preceeding zeros, this can only be displayed using a format - Zx. shows numeric values , to length x, with zeroes padded at the front. You can also put this result into a character if you want to retain the format outside the SAS system.
So something like:
length result $50; set have; var1="(1234)"; var2=5555; result=cats(put(tranwrd(var1,"()"),z6.),put(var2,best.)); run;
Will put var1 without () into 6 characters padding the front with zeroes to make the length, then concatenating the var2 to this to form a final character result. You could convert this reult to numeric and apply a Zx. format where x is the total length of var1+var2 if you like.
Need further help from the community? Please ask a new question.