Hi Team,
At the outset I would like to wish you a Merry Christmas.
Secondly,
I have a variable with codes and description comined under a single variable like shown.
Codes
111 Diabetes
222 Cancer
333 Diabetes low
444 Diabetes High
I had to seperate the codes from the description. My code is as follows;
data codes;
set Bench;
code2=strip(subsr(code,1,3));
run;
Even then I get the trailing spaces in code2 variable and its length remains the same as the original variable????
Could you help me remove the spaces?i could not acheive it with the trim either!!
Regards
Is there an issue with blanks or just with the new variables length? If it is the latter, is it corrected if you add a length statement? e.g.:
data codes;
set Bench;
length code2 $3;
code2=strip(substr(code,1,3));
run;
Is there an issue with blanks or just with the new variables length? If it is the latter, is it corrected if you add a length statement? e.g.:
data codes;
set Bench;
length code2 $3;
code2=strip(substr(code,1,3));
run;
Thanks a lot.
Karun,
Scan(), substr(), trim(), strip() and many other character functions do NOT assign length to your new variable, they only inherit the length of the variables they are working on. In your case, "code2" will have the same length as "code" if you don't explicitly assign a length to it.
Haikuo
update for your code:
data have;
input code $&100.;
cards;
111 Diabetes
222 Cancer
333 Diabetes low
444 Diabetes High
;
data want;
set have;
length code2 $3;
code2 = left(code);
run;
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!
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.