Hi all,
I am trying to search an array of character variables for the presence of certain values. The variable can take on values that are composed entirely of numerals, or are composed of letters and numerals. I am using the following code:
libname hcup 'e:\h-cup';
data name1;
set hcup.masterlong;
array dx $ dx1-dx25;
ppi = 0;
do over dx;
do i = '67000' , '03810' , '0381 ' , '03811' , '03819' , '0382 ' , '0383 ', '99590' , '99591';
if dx = i then ppi = 1;
else ppi = ppi;
end;
end;
run;
When I run the program, I get the following message:
NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
13:21 13:31 13:41 13:51 13:61 13:71 13:81 13:90 13:100 15:20
I then get an additional note every time a letter containing value is found in one of the array variables. SAS is converting the character values I am specifying for the index variable i into numeric values. This is unacceptable because the leading zeroes are important, a value of "03811" means something different than a value of "3811."
I don't understand why this is happening. Everything I've read says that it's fine to use character values for an index variable, as long as you don't mix character an numeric values for the same index variable, and the character strings are all the same length (note that I have added an extra space after four digit values).
I am using 9.4, if that matters.
Thx
I think the input data hcup.masterlong has numeric variable "I" causing the note.
I don't know what's causing your issue but this is what I would have coded:
You need to set ppi=0 outside of the loop otherwise you'll reset it to 0 every time you don't find it.
ppi=0;
do over dx;
if dx in ('67000' , '03810' , '0381 ' , '03811' , '03819' , '0382 ' , '0383 ', '99590' , '99591' ) then ppi = 1;
end;
I can't seem to repeat your "Note", on both 9.4 and 9.3. So I suspect it must have been something else. If you really suspect it is index 'i' issue, then you may want to test out the following to eliminate the index 'i':
data have;
input dx1$ dx2$;
cards;
03811 2541
0382a 6500
;
data name1;
set have;
array dx $ dx1-dx2;
ppi = 0;
do over dx;
if whichc(dx,'67000' , '03810' , '0381 ' , '03811' , '03819' , '0382 ' , '0383 ', '99590' , '99591')>0 then
do;
ppi=1;
leave;
end;
end;
run;
Regards,
Haikuo
I think the input data hcup.masterlong has numeric variable "I" causing the note.
This must be it!
Yes, that was the problem. Thanks!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.