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

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

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.

View solution in original post

5 REPLIES 5
Shmuel
Garnet | Level 18

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.

David_Billa
Rhodochrosite | Level 12
Thanks. Any other ways to achieve the excepted results?
PaigeMiller
Diamond | Level 26

@David_Billa wrote:
Thanks. Any other ways to achieve the excepted results?

Why is the code from @Shmuel not acceptable? It clearly works.

--
Paige Miller
ballardw
Super User

@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: 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
  • 5 replies
  • 2065 views
  • 3 likes
  • 5 in conversation