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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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