BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Junyong
Pyrite | Level 9

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

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;

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

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;
Tom
Super User Tom
Super User
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?

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 1012 views
  • 0 likes
  • 3 in conversation