How can I get 16 characters of a variable starting from right and fill blank spaces with zeros?, example:
Var 1 Minimum has 6 characters and is incremented
Var 2 Always has 3 characters
Var1 Var2
123456 100
1234567 100
12345678 100
I want to have result
var3
0000000123456100
0000001234567100
0000012345678100
Is Var1 character or numeric?
Here's one way. Pick the appropriate for the var1 variable type:
data example; Var1Num= 123456; var2 = 100; var1char = '123456'; var3num = cats(put(var1num,z13.),var2); var3char= cats(put(input(var1char,best16.),z13.),var2); run;
Is Var1 character or numeric?
Here's one way. Pick the appropriate for the var1 variable type:
data example; Var1Num= 123456; var2 = 100; var1char = '123456'; var3num = cats(put(var1num,z13.),var2); var3char= cats(put(input(var1char,best16.),z13.),var2); run;
Something like:
data want; set have; length var3 $16; var3=cats(put(var1,z13.),put(var2,z3.)); run;
Putting a value into a Zx. format padds out the number with '0' characters to thelength specified.
@Angel_Saenz wrote:
var1 and var2 are numeric, butI need var3 char16 because I need to marge with other var (char16)
Set the Length for the desired variable before assigning the value:
Length var3 $ 16.;
That will set the length instead of using the default coming from the CATS function.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.