DATA Step, Macro, Functions and more

Convert column representing date into SAS date column

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Convert column representing date into SAS date column

Hi, I've to import a database table into a SAS table but I want one of the columns being imported which represents the time period to be converted from a character to a SAs date column.

The orginal period column is in character format as, for example, YYYY-MM-DD  (such as 2013-09-01) but I would like it to be in the format 01SEP2013 as a SAs date column. Here is my code:

  

/* This step imports a file from the DW into a library called current on the C drive */

data current.dos_data;

set mysqlsvr.dos_date_of_supply;

format period default=DATE9.;

informat period default=DATE9.;

run;


Accepted Solutions
Solution
2 weeks ago
PROC Star
Posts: 7,363

Re: Convert column representing date into SAS date column

[ Edited ]
data have;
  input period $10.;
  cards;
2013-09-01
;

data want (drop=_:);
  set have (rename=(period=_period));
  format period date9.;
  date=input(_period,yymmdd10.);
run;

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
Solution
2 weeks ago
PROC Star
Posts: 7,363

Re: Convert column representing date into SAS date column

[ Edited ]
data have;
  input period $10.;
  cards;
2013-09-01
;

data want (drop=_:);
  set have (rename=(period=_period));
  format period date9.;
  date=input(_period,yymmdd10.);
run;

Art, CEO, AnalystFinder.com

 

Occasional Contributor
Posts: 10

Re: Convert column representing date into SAS date column

Thank you

PROC Star
Posts: 1,561

Re: Convert column representing date into SAS date column

You can do it on the fly

data CURRENT.DOS_DATA;
  set MYSQLSVR.DOS_DATE_OF_SUPPLY(rename=(PERIOD=PERIODC));
  format PERIOD date9.;
  PERIOD=input(PERIODC,yymmdd10.);
run;
Occasional Contributor
Posts: 10

Re: Convert column representing date into SAS date column

Thanks - much appreciated.


☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 101 views
  • 0 likes
  • 3 in conversation