Pyrite | Level 9

## INPUT and PUT in IML

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
SAS Super FREQ

## Re: INPUT and PUT in IML

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
SAS Super FREQ

## Re: INPUT and PUT in IML

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;``````
Super User

## Re: INPUT and PUT in IML

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?
From The DO Loop