I've a variable (Test) values as follows. It's a character variable. I want to convert only the value 21183 to 30DEC2017 and still it should be a character variable.
Data As is:
| Test |
| 21183-23-TUSE-GHU |
Data To be:
| Test |
| 30DEC2017-23-TUSE-GHU |
data test;
length test $100;
test = "21183-23-TUSE-GHU";
index = indexc(test,'-');
test = put(input(substr(test,1,index-1),5.),date9.) !! substr(test,index);
drop index;
run;
Ask yourself if it wouldn't be better to use YYMMDDD10. instead of DATE9.
One way
data _null_;
a='21183-23-TUSE-GHU';
b=cats(put(input(scan(a, 1, '-'), 8.), date9.), substr(a, indexc(a,'-')));
put b=;
ruN;
@David_Billa wrote:
I've a variable (Test) values as follows. It's a character variable. I want to convert only the value 21183 to 30DEC2017 and still it should be a character variable.
Data As is:
Test 21183-23-TUSE-GHU
Data To be:
Test 30DEC2017-23-TUSE-GHU
Where did the 21183 come from in the first place? If you created that value then show use how as that would be the place to do create the correct value to begin with.
BTW replacing 5 characters with 9 in the same variable may not be desired as you may exceed the current defined length of the variable and have truncation as a result.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.