BookmarkSubscribeRSS Feed
viji154
Calcite | Level 5

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

4 REPLIES 4
viji154
Calcite | Level 5

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 ?

Tom
Super User Tom
Super User

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.;
unison
Lapis Lazuli | Level 10

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;
-unison

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 587 views
  • 0 likes
  • 4 in conversation