BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi friends,
I was trying PATIENT=COMPRESS('0'||TRIM(PATID));so it convert character

patid

123
234
534
334
232
122


but i want every patid include with zero and it must be numericplease send me immediately


Thanku advance
2 REPLIES 2
Olivier
Pyrite | Level 9
Hello.

You can try PATIENT = PUT(PATID,Z4.) ;
Format Zx. displays integers with leading zeros on x digits.

Good luck.
Olivier
Cynthia_sas
Diamond | Level 26
Hi!
Remember that internally, SAS will NOT store a leading zero as part of a numeric variable, so you only need to use the z4. format for display of the leading zero. So in my code below, you can display the numeric patient id either with the best4. format (no leading zeros) or with the z4. format (display leading zero). To turn a CHARACTER patient ID into a NUMERIC patient ID, you need to use the INPUT function.

To "prepend" a zero onto a character variable, you could use the technique that you originally showed, but your patient id will remain character.

IF patient ID is already NUMERIC, then you can turn it into a CHARACTER string with a leading zero using the PUT function.

But it sounded to me like your patient ID was already character and you wanted it to be numeric and that will take the INPUT function. But, that also requires that you use the Z4. format in order to display patient id once it is a number. See the attached code.

cynthia
[pre]
*** the code;
data testit;
input charpat $ numpat;
** convert charpat to new numeric var;
newnumpat1 = input(charpat,4.);

** convert numpat to new character var;
newcharpat1 = put(numpat,z4.);

** use concat to put zero onto char patient id;
** but patient id remains character;
newcharpat2 = '0'||trim(charpat);

format numpat best4. newnumpat1 z4.;
return;
datalines;
123 123
234 234
534 534
334 334
232 232
122 122
;
run;

proc print data=testit;
run;
[/pre]

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 2 replies
  • 3865 views
  • 0 likes
  • 3 in conversation