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
Rhodochrosite | Level 12

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

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!

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.

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
  • 2962 views
  • 0 likes
  • 5 in conversation