+ Reply to Thread
Results 1 to 5 of 5

Thread: Date Formats

  1. #1
    Points: 3,999, Level: 40
    Level completed: 25%, Points required for next Level: 151

    Posts
    305
    Thanks
    16
    Thanked 15 Times in 15 Posts

    Date Formats



    I have a question about date formats.

    I have a variable called date in which the year and month of cost data was stored. For example, if date=200601 that means January of 2006. So, the first 4 numbers represent year and the last 2 represent month.

    I want SAS to understand that this is a date and represents Year-Month but I'm not quite sure how to do so? I think utimately I'd like for these values to be formatted so that they appear as JAN2006 (instead of 200601). I'm not quite sure how to do this though.
    Thanks!

  2. #2
    Test of Gnomality
    Points: 8,883, Level: 63
    Level completed: 45%, Points required for next Level: 167
    hlsmith's Avatar
    Posts
    1,647
    Thanks
    106
    Thanked 276 Times in 269 Posts

    Re: Date Formats

    Might be a more elegant way to do it, but since your dates will always be 6 digits, you may be able to create a new variable using a substring or numeric placement in your numbers. Grab month and convert, then tell it to add year. Sorry for not providing code.

  3. #3
    Points: 3,999, Level: 40
    Level completed: 25%, Points required for next Level: 151

    Posts
    305
    Thanks
    16
    Thanked 15 Times in 15 Posts

    Re: Date Formats

    I want to eventually graph the results (with dates on the x-axis). So right now SAS reads my date variable from low to high so my dates will be in order. However, if I create a new variable from scratch then it will read it alphabetically (April will come before February alphabetically).


    What if I want to use PROC SGPLOT to graph costs vs. dates. What if I want the x-axis to ONLY contain tick marks for every 6 months (200601, 200607, 200701, 200707......). Is there a way I can accomplish this?

  4. #4
    Test of Gnomality
    Points: 8,883, Level: 63
    Level completed: 45%, Points required for next Level: 167
    hlsmith's Avatar
    Posts
    1,647
    Thanks
    106
    Thanked 276 Times in 269 Posts

    Re: Date Formats

    I had been sitting here feeling bad since I pretty much phoned in that last post. The following should work for your first post, just substitute the correct date format you want (lots of them available online).

    Code: 
    Data test;
    input cDate $6.;
    
    Date = input( Compress( cdate || '01') , yymmdd10.) ;
    Format date mmddyy10.;
    datalines;
    200906
    run;
    proc print; run;

  5. The Following User Says Thank You to hlsmith For This Useful Post:

    lancearmstrong1313 (08-15-2012)

  6. #5
    Points: 3,999, Level: 40
    Level completed: 25%, Points required for next Level: 151

    Posts
    305
    Thanks
    16
    Thanked 15 Times in 15 Posts

    Re: Date Formats


    Haha don't feel bad! I actually found an almost identical code from a google search so thank you very much! I will give it a try

    * it worked
    Last edited by lancearmstrong1313; 08-15-2012 at 06:24 AM.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats