I'm trying to convert YYYY-MM character value to numeric with the format yymmd7. but it's not working as it producing null values. Desired output is same as source dataset but with numeric data type. Any guidance?
data have; input Start_Mo $ End_Mo $; datalines; 2017-03 2017-09 2016-03 2018-09 ; run; data want; set have; Start_mo_num=input(Start_Mo,best32.); End_mo_num=input(End_Mo,best32.); format start_mo_num End_mo_num yymmd7.; run;
You need to supply a day in order to convert the input into sas date, as in next example:
data a;
dt = '2017-08';
date = input(cats(dt,'-01'),yymmdd10.);
format date yymmd7.;
run;
chaeck dataset a (the result of above code) and adapt your code.
You need to supply a day in order to convert the input into sas date, as in next example:
data a;
dt = '2017-08';
date = input(cats(dt,'-01'),yymmdd10.);
format date yymmd7.;
run;
chaeck dataset a (the result of above code) and adapt your code.
data test;
in = "2020-08";
out = input(compress(in,'-'),yymmn6.);
run;
@David_Billa wrote:
Thanks. Any other ways to achieve the excepted results?
Why is the code from @Shmuel not acceptable? It clearly works.
@David_Billa wrote:
Thanks. Any other ways to achieve the excepted results?
data have; input Start_Mo $ End_Mo $; startdate = input(start_mo,anydtdte.); enddate = input(end_mo, anydtdte.);
format startdate enddate date9.; datalines; 2017-03 2017-09 2016-03 2018-09 ; 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.