🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 03-27-2020 07:39 PM
(878 views)
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.
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I don't see how what format you have attached to the variable (year. vs yymmddn.) matter? The value it contains still needs to be a date value. Or did you mean that you want to create your different patterns of digit strings that you then convert into pseudo numbers?