BookmarkSubscribeRSS Feed
deleted_user
Not applicable
What kind of function to use that will result in preceding zeros being recognized by SAS?
For example, I have diagnosis codes that are given in character format as ('00345', '011' , '67893', '1888' etc.)

The following statement appears to read the first 2 codes as '345' and '11':

CC = PUT(LEFT(PUT(DIAG,8.)),$&FMNAME..);

What do I need to change?
3 REPLIES 3
LinusH
Tourmaline | Level 20
Sorry, I can't reproduce your problem. For me CC comes out as 00345 if I use "10" as &FMNAME. Maybe it is the format that is the problem? Perhaps if you output the format to a CNTLOUT table (PROC FORMAT) will give you a hint.
If not, try to split up your assignment statement into several using intermediate variables, togehter with a PUT _ALL_;

/Linus
Data never sleeps
GertNissen
Barite | Level 11
What type is DIAG (char or num) ? What you might are looking for is z.

Look at the two small examples below:
[pre]
data test;
input DIAG $;
num = input(diag,best.);
char = put(num,z5.);
put _all_;
datalines;
00345
011
67893
1888
;
run;[/pre]

[pre]
data test;
input DIAG;
char = put(diag,z5.);
put _all_;
datalines;
00345
011
67893
1888
;
run;[/pre]
Patrick
Opal | Level 21
Hi Liv

What your code shows is that your variable DIAG is actualy numeric. The statement 'PUT(DIAG,8.)' uses the numeric format w.d.

The result of this 'put' is a character string without leading zeros.

As Geniz demonstrates: If you want leading zeros you have to use the Zw.d format; 'PUT(DIAG,z8.)'

No clue how your outer put statement using $&FMNAME.. will digest this string with leading zeros. Does this format expect such a string?

HTH
Patrick

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 1363 views
  • 0 likes
  • 4 in conversation