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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1649 views
  • 3 likes
  • 5 in conversation