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!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.