BookmarkSubscribeRSS Feed
keen_sas
Quartz | Level 8

Hi All , I am using VTYPE and PUTN function in IF-THEN-ELSE condition ,output is fine , but have a doubt in the execution as below, since it is throwing a NOTE in the log ,which should not happen.

data want;
 set sashelp.rent; 
 if vtype(date)='N' then mdate=putn(date,vformat(date));
 else if vtype(date)='C' then mdate=scan(date,1,'T');
run ;


NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      26:42   
NOTE: There were 10 observations read from the data set SASHELP.RENT.
NOTE: The data set WORK.WANT has 10 observations and 3 variables.
NOTE: Compressing data set WORK.WANT increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.


Concern: As per the data, the DATE variable is numeric and it is getting satisfied in the first 
IF condition. But why it is checking for second ELSE IF condition and throwing a NOTE
(Numeric conversion) in the log. Similarly in the below condition also ,
when the first IF condition is not satisfied but still executing with a NOTE (Character conversion )
in the log .Ideally it should not happen , what could be the issue for this if-then-else conditions
and how to resolve it with out any CONVERSION notes in the log. data want1; set want; if vtype(mdate)='N' then mdatenew=putn(mdate,vformat(mdate)); else if vtype(mdate)='C' then mdatenew=mdate; run ; NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column). 25:41 NOTE: There were 10 observations read from the data set WORK.WANT. NOTE: The data set WORK.WANT1 has 10 observations and 4 variables. NOTE: Compressing data set WORK.WANT1 increased size by 100.00 percent. Compressed is 2 pages; un-compressed would require 1 pages.
2 REPLIES 2
s_lassen
Meteorite | Level 14

Your problem is that the statements for the character assignment and PUTN function is still in the code, even though they do not get executed. The notes you get are compile-time, and the compiler does not check if the code will be executed, it just compiles it.

 

You will either have to live with it (I would probably avoid such notes in production jobs), or do something else. 

Patrick
Opal | Level 21

Agree with @s_lassen 's explanation and also that we should avoid such conversion notes BUT: I feel your case here is the exception to the rule. It's just a compiler Note and there isn't actually such a conversion happening. So in your case just adding a comment to the code which explains the SAS note and that it's a non-issue would be good enough for me for production worthy code.

 

Question: What should happen if there is no format attached to the variable?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 886 views
  • 0 likes
  • 3 in conversation