New User
Posts: 1

# to get left 3 digits of numeric value

Hi,

In a column, the employee code having 6 digits is mentioned . If I want to see the first 3 digit of the employee code in a column, please suggest the sas code for this.

 Employeecode first 3 digits 174078 174 121764 121 190333 190 214078 214
Super User
Posts: 9,599

## Re: to get left 3 digits of numeric value

Hi,

Assuming that the id is text:

three_chars=substr(left(id),1,3);

If number then:

three_chars=substr(put(id,6.),1,3);

Super Contributor
Posts: 281

## Re: to get left 3 digits of numeric value

if the employee code is a number, then you would need to convert it to a character first, then use Character functions to get the first three digits.

Data _null_;
employee_code = 174078; /* Numeric */
first_3_digits = INPUT(SUBSTR(PUT(employee_code,6.),1,3),3.); /* Num -> Char -> Num */
put _all_;
run;

Frequent Contributor
Posts: 102

## Re: to get left 3 digits of numeric value

Try this code;

data one; infile cards;
input @1 empid;
cards;
174078
121764
190333
214078
;
data; set; format x 3.;
x=trunc((empid/1000),3);
proc print; run;

Jim

Valued Guide
Posts: 765

## Re: to get left 3 digits of numeric value

Hi.  If EMPID is numeric ...

data one;
input empid @@;
datalines;
174078 121764 190333 214078
;

data two;
set one;
three = input(cat(empid),3.);
run;

data set TWO ...

Obs empid  three

1   174078  174
2   121764  121
3   190333  190
4   214078  214

Discussion stats
• 4 replies
• 285 views
• 0 likes
• 5 in conversation