I have a proc sql like this one, the problem is that sas remove the zero before each cust_comp_key for example FR_C_00000242 is transforming to 242 but i want to keep the zeo before 242 ...
rsubmit;
data ca_m_service_2;
set ca_m_service;
num_compte = input(substr(CUST_COMP_KEY, 6),Best12.);
run;
endrsubmit;
Thanks for help
I have a proc sql like this one, the problem is that sas remove the zero before each cust_comp_key for example FR_C_00000242 is transforming to 242 but i want to keep the zeo before 242 ... faceforpc
rsubmit; data ca_m_service_2; set ca_m_service; num_compte = input(substr(CUST_COMP_KEY, 6),Best12.); run; endrsubmit;
Thanks for help
It seems to work but now I need to transformr this vector to numeric, how can I do this ?
Numbers don't have leading zeros, or they have an infinite number of them, since the meaning of 0242 and 242 is the same number.
If you want to keep the leading zeros then keep the value as a character variable.
customer_id = substr(CUST_COMP_KEY,6);
If you want SAS to DISPLAY a number with a fixed number of digits by showing leading zeros then attached the Z format to it. But you cannot ask it just add one leading zero so that 15 become 015 and 242 becomes 0242. You can only say display, for example, 8 digits. Then when the value is less than 10,000,000 there will be enough leading zeros to display exactly 8 digits.
customer_id_as_number = input(substr(CUST_COMP_KEY,6),8.);
format customer_id_as_number z8.;
Adding a format will change the appearance to what you want:
data have;
input cust_comp_key :$13.;
datalines;
FR_C_00000242
;
run;
data want;
set have;
num_compte = input(substr(cust_comp_key,6),best.);
format num_compte z12.;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.