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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3811 views
  • 2 likes
  • 4 in conversation