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 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Multiple Linear Regression in SAS

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.

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