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

Hi,

I was trying to convert a year '2015' which is in character format into date format by using input function.
Eg : input(year, 4.) It either gives me a missing value or a value as 1965. Can some one help me what source informat should I be using

Like wise I have a column which has 3 letter month 'Feb' in character format and I used same input function and I get missing values. I tried with all possible source informats but still unable to find the right solution.

Please tell me if we can do it without concatenating year and month.

I want it individual conversion.

Thanks and Regards,
Karthik

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

 

I couldn't find informats so used some date logic to get it.  A SAS date requires a day, month and year though they don't need to be displayed. A date is the number of days since Jan 1, 1960.  

 

data have;
input year_char $ month_char $;
cards;
1990 SEP
2014 JAN
2015 MAY
;
run;

data want;
set have;

year=mdy(1, 1, input(year_char, 4.));
month=input(catt("01", month_char, "2015"), date9.);

format month monname3.;
format year year4.;
run;

proc print;
run;

 

View solution in original post

3 REPLIES 3
PGStats
Opal | Level 21

What messages do you get in the log window?

PG
Reeza
Super User

 

I couldn't find informats so used some date logic to get it.  A SAS date requires a day, month and year though they don't need to be displayed. A date is the number of days since Jan 1, 1960.  

 

data have;
input year_char $ month_char $;
cards;
1990 SEP
2014 JAN
2015 MAY
;
run;

data want;
set have;

year=mdy(1, 1, input(year_char, 4.));
month=input(catt("01", month_char, "2015"), date9.);

format month monname3.;
format year year4.;
run;

proc print;
run;

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

To get a good answer, it is a good idea to post test data (in the form of a datastep) and what the output should look like.  I guess with the below:

data want;
  year="2015";
  month="Feb";
  numeric_year=input(year,4.);
  numeric_month=month(input(cats("01",month,"2000"),date9.));
run;

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 Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 3535 views
  • 2 likes
  • 4 in conversation