BookmarkSubscribeRSS Feed
avatar
Fluorite | Level 6

I am trying to add  zero for  patient number if the length is than 7

 following code gives error

data fix_ptnt;

set FCR_ADUIT_REPORT;

format patient_id $20.;

if length(PATIENT_SRC_NO) = 6 then patient_id = '0'||strip(PATIENT_SRC_NO);

run;

 

can you please help?

 

thanks,

 

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

If you simply want to pad the ID with zeros so the value has 7 digits, then simply do

 

data have;
input patient_id $;
datalines;
1
11
111
1111
11111
111111
;

data want;
   set have;
   new_patient_id=put(input(patient_id, 8.), z7.);
run;

 

 

 

Kc2
Quartz | Level 8 Kc2
Quartz | Level 8

Right now the 0 gets only added if the length equals 6. 

Try 

if length(PATIENT_SRC_NO) < 7  then patient_id = '0'||strip(PATIENT_SRC_NO);

else patient_id=strip(PATIENT_SRC_NO);

run;

 

Tom
Super User Tom
Super User

What error does it give?

avatar
Fluorite | Level 6

 oh! I  found out the error for previous step . not for my code. it is working fine now t

 

Thank you all for your replies. All worked fine!

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

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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