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!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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