Convert character Dates to a yymmn. date format

Reply
Occasional Contributor
Posts: 14

Convert character Dates to a yymmn. date format

I have character variables values that represent a date.  An example of a date is the following:  July 2016 is displayed as 201607. What I want to do is create a scatter plot and alter the Xaxis that shows the dates, but without altering the date, I am unable to alter the Xaxis range.

 

I tried it with just the character value, but I know I am not on the right track

 

axis2 order=(201401 to 201604 by 00001);

axis1 order=(0 to 1200 by 10) minor=none;

 

So I tried to take an example This is what I am trying to do with a dataset.

 

data testdate;

length chardate $10;

infile datalines;

input chardate $;

date = input(chardate,yymmn.);

return;

datalines;

201601

201602

201603

201604

201605

201606

201601

201602

201603

201604

201605

201606

201601

201602

201603

201604

201605

201606

;

run;

Super Contributor
Posts: 406

Re: Convert character Dates to a yymmn. date format

You're on th eright track but yymmn. is a format but not an informat. here's a quick fix:

 

data testdate;
    length chardate $10 date 8;
    format date date9.;
    infile datalines;
    input chardate $;
    chardate=cats(chardate,'01');
    date = input(chardate,yymmdd8.);
    put _all_;
datalines;
...

- Jan.

Super Contributor
Posts: 406

Re: Convert character Dates to a yymmn. date format

Sory, I'm wrong. There is an informat yymmn6. Back to the drawing board.

Grand Advisor
Posts: 10,210

Re: Convert character Dates to a yymmn. date format

If you have successfully converted or created your date variable then you want to reference date literals in the order clause (so humans can understand). The only way that SAS accepts date literal values is 'ddMONyy'd or 'ddMONyyyy'd.

 

So with SAS date values instead of

axis2 order=(201401 to 201604 by 00001);

use

axis2 order=('01JAN2014'd to '01APR2016'd by month);

 

When values in an order clause a given as date, time or datetime literals then you can use special incrementers of Year Month Week for dates and minute or hour for times and DTday and such for datetime values.

Note that dates will usually generate a note in the log about tick values on the axis are not uniformly spaced (months have different numbers of days). This is normal and not an issue if you see it.

Ask a Question
Discussion stats
  • 3 replies
  • 344 views
  • 0 likes
  • 3 in conversation