I convert, for example, "27mar2020"d to 202003 using PUT and INPUT as follows.
data y;
x="27mar2020"d;
y=input(put(x,yymmn6.),6.);
run;
Can one do something equivalent in IML? I don't want to use the 100*YEAR(X)+MONTH(X) approach because I use multiple formats such as yymmddn8. and year4.
proc iml;
x="27mar2020"d;
y=input(put(x,yymmn6.),6.);
/*y=100*year(x)+month(x); want to avoid*/
quit;
Thanks.
Although the PUT and INPUT functions are valid in the DATA step, the PUTN, PUTC, INPUTN, and INPUTC functions are more widely supported. Since you want to use Numeric formats, use PUTN and INPUTN. (You chould use the C versions for Character formats.)
proc iml;
x="27mar2020"d;
t = putn(x,"yymmn6.");
y = inputn(t, "6.");
print t, y;
/* or next the function calls */
y=inputn(putn(x,"yymmn6."),"6.");
print y;
Although the PUT and INPUT functions are valid in the DATA step, the PUTN, PUTC, INPUTN, and INPUTC functions are more widely supported. Since you want to use Numeric formats, use PUTN and INPUTN. (You chould use the C versions for Character formats.)
proc iml;
x="27mar2020"d;
t = putn(x,"yymmn6.");
y = inputn(t, "6.");
print t, y;
/* or next the function calls */
y=inputn(putn(x,"yymmn6."),"6.");
print y;
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 16. Read more here about why you should contribute and what is in it for you!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.