DATA Step, Macro, Functions and more

Preceeding Zeros

Reply
N/A
Posts: 0

Preceeding Zeros

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?
Super User
Posts: 5,441

Re: Preceeding Zeros

Posted in reply to deleted_user
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
SAS Employee
Posts: 174

Re: Preceeding Zeros

Posted in reply to deleted_user
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]
Respected Advisor
Posts: 4,173

Re: Preceeding Zeros

Posted in reply to deleted_user
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
Ask a Question
Discussion stats
  • 3 replies
  • 140 views
  • 0 likes
  • 4 in conversation