## how to convert numeric date variable into character date variable

Solved
Occasional Contributor
Posts: 6

# how to convert numeric date variable into character date variable

Hi,

I am trying to convert numeric date variable into character date variable.

PROC SQL;

CREATE TABLE y AS

SELECT PUT(subjid, 6.) AS subjid,

PUT(date, 20.) AS date FORMAT = YYMMDD10.

FROM x;

QUIT;

423  PROC SQL;

424    CREATE TABLE y AS

425    SELECT PUT(subjid, 6.) AS subjid,

426           PUT(date, 20.) AS date FORMAT = date9.

427      FROM x;

ERROR: Character expression requires a character format.

428  QUIT;

NOTE: The SAS System stopped processing this step because of errors.

both subjid and date are numeric variables and i want to convert into character variables for merging.

Are there any other ways of doing this conversion?

Thank you

Anu.

Accepted Solutions
Solution
‎10-19-2016 11:42 AM
Occasional Contributor
Posts: 13

## Re: how to convert numeric date variable into character date variable

[ Edited ]

Editor's note:  Thanks to Aishwarya for showing how to use the PUT function to apply the YYMMDD10. format.   Using the YYMMDD10. format along wtih the PUT function will convert the SAS date to a character string in the format of YYYY-MM-DD.

Hi Aishwarya,

For the conversion of numeric value to character value try the following code

``````PROC SQL;

CREATE TABLE y AS

SELECT PUT(x.subjid, 6.) AS subjid,

PUT(x.date, YYMMDD10. ) AS date

FROM x;

QUIT;
``````

Now this column was converted into character so you can not applied numeric formate on that

All Replies
Solution
‎10-19-2016 11:42 AM
Occasional Contributor
Posts: 13

## Re: how to convert numeric date variable into character date variable

[ Edited ]

Editor's note:  Thanks to Aishwarya for showing how to use the PUT function to apply the YYMMDD10. format.   Using the YYMMDD10. format along wtih the PUT function will convert the SAS date to a character string in the format of YYYY-MM-DD.

Hi Aishwarya,

For the conversion of numeric value to character value try the following code

``````PROC SQL;

CREATE TABLE y AS

SELECT PUT(x.subjid, 6.) AS subjid,

PUT(x.date, YYMMDD10. ) AS date

FROM x;

QUIT;
``````

Now this column was converted into character so you can not applied numeric formate on that

Occasional Contributor
Posts: 6

## Re: how to convert numeric date variable into character date variable

Thank you

Occasional Contributor
Posts: 13

Welcome

New Contributor
Posts: 2

## Re: how to convert numeric date variable into character date variable

Hi please try the below one....in the below example shows how to convert numeric date values to character ones..

data dates;
informat A date9.;
input A;
cards;
13/APR/1999
01/JAN/1960
31/JAN/1960
;
run;

data converted;
set dates;
dates_char = put(a,date9.);
run;

Contributor
Posts: 31

## Re: how to convert numeric date variable into character date variable

[ Edited ]

Hi,

how is it possible to convert a numeric date field into character value using an expression in SAS Data Integration Studio?