Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting Char formatted Date field to SAS Date

Status
Not open for further replies.

lora

Programmer
Dec 1, 1999
43
US
I'm almost brand new to both sas and sql - hopefully this is easy!

I've got an effective date field coming from a mainframe data file. It was created in mainframe sas as a character field. Value is yymmdd. I want to convert this to a sas date format to use the various date functions for summing by data by year, quarter, etc...

So far I've tried:

proc sql;
create table datet as
select
input (effdate, yymmddw.) AS date,
input (effdate, yymmddw.) as datef format=date9.
from cd.wcfile (firstobs = 1 obs = 10)
;
quit;

example is input file has character 030514 for May 14, 2003 - but output is date=30514 datef=18JUL2043.

Thanks in advance to anyone who can help!!
Lora

 
What you are missing is a length on the format.

try this:
Code:
proc sql;
create table datet as                 
select                         
 input (effdate, yymmdd8.) AS date,
  input (effdate, yymmdd8.) as datef format=date9.
from cd.wcfile (firstobs = 1 obs = 10)
;  
quit;

I hope that this helps you out.
Klaz
 
Yeah, when reading the format documentation (as you obviously have like a good programmer) the W part at the end of the format (or informat in this example) refers to width of the formatted string. The d which appears on numeric formats refers to the number of decimal places.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Thanks to both of you...I've had several 'DUH' moments as I'm so new to this! The only other issue i'm having is since its character I get an error in the log that its an invalid data type - but it does do the conversoin. There must be a way to convert character to numeric first to avoid the error. I'll keep hunting for that one!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top