BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Denali
Quartz | Level 8

Hi,

 

The indentified variable is currently listed as character $500. How can I shorten the length to $8 and add leading zeros to those numbers shorter than 8 characters? Thank you.

 

proc contents results: 

record_id Char 500 $500.

 

 

 

Proc print results: 

Obs record_id
1 25481
2 27775
3 167205
4 168552
5 195018
6 293336
7 303971
8 336269
9 360908
10 362220
11 00362383
12 370550
13 447997
14 00496297
15 499403
16 506068
17 506914
18 514282
19 525407
20 584554
21 681037
22 775671
23 788309
24 840175
25 862188
26 35044537
1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16
Please try below code to derive record_id2 variable

record_id2=put(input(record_id,best.),z8.);
Thanks,
Jag

View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16
Please try below code to derive record_id2 variable

record_id2=put(input(record_id,best.),z8.);
Thanks,
Jag
Denali
Quartz | Level 8

Thank you so much! It worked! 

Ksharp
Super User
data have;
input record_id	$;
length want $ 8;
want=record_id;
want=translate(right(want),'0',' ');
cards;
25481
27775
;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 641 views
  • 0 likes
  • 3 in conversation