BookmarkSubscribeRSS Feed
Nasya
Obsidian | Level 7

Hi,

 

I need to hardcode the existing date value which is numeric for one of the ID's which are character in nature. There are multiple records for a single ID.

Here is the example,

 

ID                  Date                         Date

001-01         26-Feb-2018           27-Feb-2018

001-01        26-Feb-2018            27-Feb-2018

002-02         27-March-2018        27-March-2018

002-02         27-March-2018         27-March-2018

002-02         27-March-2018         27-March-2018

002-02         27-March-2018          27-March-2018

003-03        01-Jan-2017                01-Jan-2017

003-03        01-Jan-2017                  01-Jan-2017

003-03        01-Jan-2017                01-Jan-2017

004-04        08-Nov-2016               08-Nov-2016

004-04        08-Nov-2016                08-Nov-2016

005-05        06-March-2018             06-March-2018

005-05        06-March-2018              06-March-2018

005-05        06-March-2018               06-March-2018

005-05        06-March-2018                06-March-2018

 data raw ;
       set dm;
        by ID;
   
    if ID= "001-01" and Date= "26FEB2018" then do;
       Date="27FEB2018";
       end;
  
run;
 

 I see this following error with the above code:

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).

Any suggestions please.

Thank you,

 

Regards,

Nasya       

7 REPLIES 7
ybolduc
Quartz | Level 8

You simply need to add d after the closing quote of your date string to make SAS understand it needs to treat it as a date and not a string.

 

Thanks,

ballardw
Super User

Is your "date" variable character or numeric with a format attached?

It is best to show messages from the log by copying the data step or procedure code along with the messages from log (One copy) and paste into a code box opened on the forum with the {I} menu icon.

That way see everything.

 

If the date variable is actually numeric you need to use the form "27FEB2018"d or "28FEB2018'd to tell SAS that the value is a date literal and not a character value.

Nasya
Obsidian | Level 7

Yes, date is numeric with a format E8601DA10.

Reeza
Super User

Are the date variables character? If so, thats not a good idea and you should convert them. 

 

If they are characters your match string has to be exactly the same, which in this case it's clearly not.

 

Data is shown as 28-Feb-2018, but your comparison string is in the date9 format, 28Feb2018. If it's even a different case or an extra space it won't match. 

 

If it's a number, just add the d after the quotation marks to tell SAS that it's a date. 
In fact, since it says character to numeric conversion, I suspect it's actually a date, so adding the d is all you need.

 

d -> date literal

n -> name literal

t -> time literal

dt -> datetime literal.

 

  if ID= "001-01" and Date= "26FEB2018"d then Date="27FEB2018"d;
Nasya
Obsidian | Level 7

Date is a numeric type with format E8601DA10. in the original data set.

Yes you are right: This is how the date is seen in the original data set

For example 2018-02-27 but needs to be hardcoded as 26FEB2018.

Just adding d isn't working because of the above condition?

How to handle this?

Thank you,

 

Regards,

Nasya

Reeza
Super User

@Nasya wrote:

Date is a numeric type with format E8601DA10. in the original data set.

Yes you are right: This is how the date is seen in the original data set

For example 2018-02-27 but needs to be hardcoded as 26FEB2018.

Just adding d isn't working because of the above condition?

How to handle this?

Thank you,

 

Regards,

Ep**bleep**ha


Post your modified code and log. Including D alone should fix the issue, since SAS requires dates to be specified in the date9 format with the d. What makes you think it's not working?

ybolduc
Quartz | Level 8

Hi Nasya,

 

The format you apply on your columns does not matter here. When using date constants, SAS expects them to be in a given format. As I mentionned earlier, if you add a d at the end like '26FEB2018'd, you should obtain the behaviour you are looking for.

 

For more details, please refer to the SAS Documentation: http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000780334.htm

 

Thanks,

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 7 replies
  • 6528 views
  • 0 likes
  • 4 in conversation