BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aishwarya
Calcite | Level 5

Hi,

Need help please..

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.

1 ACCEPTED SOLUTION

Accepted Solutions
DJChavda
Obsidian | Level 7

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

View solution in original post

5 REPLIES 5
DJChavda
Obsidian | Level 7

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

gowthamgsas
Calcite | Level 5

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;


niespolo
Obsidian | Level 7

Hi,

 

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

 

Thanks in advance.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 59976 views
  • 1 like
  • 4 in conversation