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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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