BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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):(Column).
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):(Column).
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.
3 REPLIES 3
DanielSantos
Barite | Level 11
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
data_null__
Jade | Level 19
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".

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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