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
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;
What messages do you get in the log window?
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;
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.