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
SAS Super FREQ
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]

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!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

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