Taking over code from colleague who left company.
Not sure I understand what the line 'else if...' is doing as I get the following error.
Thank you.
Error" Invalid third argument to function SUBSTR
id2=0012312345 Pat_id=55555 Enc_type=office visit
region=NY id2=12312345 id=12312345 age=30 bmi 20.8 _ERROR_=1 _N_=6
Variable id2 is text length 11:
id2
0012312345
0023454321
0034565656
0099912345
Code:
data two;
set one (rename=(id2=id3));
by pat_id;
region='NY';
IF region='MN' then ID2=compress(ID3);
Else if region='NY' then ID2=compress(put(input(substr(id3, 3, 11),11.),11.) );
id = input(id2,15.);
run;
id3 is 10 chars long and substr 3rd argument is 11. Although length is specified as 11, thus check if it ever exceeds 10 chars, if not change to substr(id3, 3, 10)
i have a supplementary Q: does anyone know if you can specify a 3rd argument as missing which would indicate: from the 2nd argument to the end of the string?
id3 is 10 chars long and substr 3rd argument is 11. Although length is specified as 11, thus check if it ever exceeds 10 chars, if not change to substr(id3, 3, 10)
i have a supplementary Q: does anyone know if you can specify a 3rd argument as missing which would indicate: from the 2nd argument to the end of the string?
@pau13rown wrote:
i have a supplementary Q: does anyone know if you can specify a 3rd argument as missing which would indicate: from the 2nd argument to the end of the string?
Yes, just don't define a 3rd argument: substr(id3, 3)
great to know, i always tried "substr(id3, 3, )" with a superfluous comma
@lam1 wrote:
Taking over code from colleague who left company.
Not sure I understand what the line 'else if...' is doing as I get the following error.
Thank you.
Error" Invalid third argument to function SUBSTR
id2=0012312345 Pat_id=55555 Enc_type=office visit
region=NY id2=12312345 id=12312345 age=30 bmi 20.8 _ERROR_=1 _N_=6
Variable id2 is text length 11:id2
0012312345
0023454321
0034565656
0099912345
Code:
data two;
set one (rename=(id2=id3));
by pat_id;
region='NY';IF region='MN' then ID2=compress(ID3);
Else if region='NY' then ID2=compress(put(input(substr(id3, 3, 11),11.),11.) );
id = input(id2,15.);
run;
That looks to me like a piece of unfinished messy code which you better re-write from scratch
Here region gets set to NY so below IF condition will never be true.
region='NY'; IF region='MN' then ID2=compress(ID3);
That looks like an attempt to convert a string of digits to a number.
Else if region='NY' then ID2=compress(put(input(substr(id3, 3, 11),11.),11.) ); id = input(id2,15.);
There is absolutely no need to first try and strip leading zeros from the string for such a conversion. Code as below should do.
id=input(id3,? best32.);
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.