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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 3 replies
  • 771 views
  • 0 likes
  • 4 in conversation