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