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

Hello,

I have a numeric variabled called "Period_YYYYMM", which contains values such as "201402". I need to convert it into a character variable which should display the values as for instance "28FEB2014". I imagine this requires a combination of the informat yymmn6., the format date9, the intnx-function (to find the last day per month), and a few put- and input- functions; however I seem unable to figure out the correct application of those. Can someone please offer some guidance on this?

Thanks for your time

1 ACCEPTED SOLUTION

Accepted Solutions
DBailey
Lapis Lazuli | Level 10

Do you need it to be character or just display date9.?

data want;

var1=201402;

var2=intnx('month',input(put(var1,$6.),yymmn6.),0,'end');

format var2 date9.;

run;

to be truly character:

data want;

var1=201402;

var2=put(intnx('month',input(put(var1,$6.),yymmn6.),0,'end'),date9.);

run;

View solution in original post

3 REPLIES 3
Reeza
Super User

It always help if you've posted what you tried Smiley Happy

DBailey
Lapis Lazuli | Level 10

Do you need it to be character or just display date9.?

data want;

var1=201402;

var2=intnx('month',input(put(var1,$6.),yymmn6.),0,'end');

format var2 date9.;

run;

to be truly character:

data want;

var1=201402;

var2=put(intnx('month',input(put(var1,$6.),yymmn6.),0,'end'),date9.);

run;

EinarRoed
Pyrite | Level 9

Worked like a charm. Thanks grand wizard. Smiley Happy

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 10142 views
  • 0 likes
  • 3 in conversation