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,
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;
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;
What error does it give?
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!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.