Help using Base SAS procedures

SAS problem in log (very strange..)

Reply
N/A
Posts: 0

SAS problem in log (very strange..)

Hello dears SAS users
Have a look on it :
If i submit the following code (very basic code):
data STRANGE_LOG;
set sashelp.class(obs=3);
if vtype(age) eq "N" then do;
test=put(age, 8.);
end;
else if vtype(age) eq "C" then do;
test=age;
end;
run;
I will get the following log :
NOTE: Numeric values have been converted to character values at the places given by:
(Line)Smiley SadColumn).
390:12
NOTE: There were 3 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.STRANGE_LOG has 3 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

But if i submit this code :

data STRANGE_LOG2;
set sashelp.class(obs=3);
if vtype(age) eq "N" then do;
test=put(age, 8.);
end;
run;

I will get this in my log:
NOTE: There were 3 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.STRANGE_LOG2 has 3 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

So why it's written in the first case
NOTE: Numeric values have been converted to character values at the places given by:
(Line)Smiley SadColumn).
390:12
and not in the second case ?

Why there is this note, even if the process will never go into the
else if vtype(age) eq "C" then do;
test=age;
end; ?????
because age is numeric.

It's very important because i'm currently working for a big pharma and it's strictly
forbidden to have the note "Numeric values have been converted to character values.." in the log.

Could you help me please ?

Thank you for your answers.
Super Contributor
Posts: 474

Re: SAS problem in log (very strange..)

Hi.

You got SAS confused with the first datastep.

These two statements are ambiguous

[pre]test=put(age, 8.);

test=age[/pre]

Being age a NUMERIC var on SASHEP.CLASS, SAS inherited the type for the test var.

You should explicitly declare TEST as a character variable, through the LENGTH statement.

http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000218807.htm

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
Respected Advisor
Posts: 3,777

Re: SAS problem in log (very strange..)

as you can see the conversion message is written even if the statement is not executed.

A simple way to "fix" it would be to use VVALUE function as

[pre]
data STRANGE_LOG;
set sashelp.class(obs=3);
length test $8;
test = vvalue(age);
format age 8.3; *format of choice;
run;
[/pre]

Or if you don't use SAS V9 you will need to determine the variable type and then write some "flex code".
N/A
Posts: 0

Re: SAS problem in log (very strange..)

Thank you
Ask a Question
Discussion stats
  • 3 replies
  • 119 views
  • 0 likes
  • 3 in conversation