BookmarkSubscribeRSS Feed
mprasannna
Calcite | Level 5

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.

Employeecodefirst 3 digits
174078174
121764121
190333190
214078214
4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

AhmedAl_Attar
Ammonite | Level 13

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;

 

Jim_G
Pyrite | Level 9

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

MikeZdeb
Rhodochrosite | Level 12

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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