SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Character values for index variable being converted to numeric

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Character values for index variable being converted to numeric

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)Smiley SadColumn).

      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


Accepted Solutions
Solution
‎06-12-2014 03:39 PM
Respected Advisor
Posts: 3,777

Re: Character values for index variable being converted to numeric

I think the input data hcup.masterlong has numeric variable "I" causing the note.

data _null_;
   i=
1;
  
do i = '67000' , '03810' , '0381 ' , '03811' , '03819' , '0382 ' , '0383 ', '99590' , '99591';
     
put 'NOTE: ' i=;
      end;
  
run;

NOTE:
Character values have been converted to numeric values at the places given by: (Line)Smiley SadColumn).
     
18:11   18:21   18:31   18:41   18:51   18:61   18:71   18:80   18:90  
NOTE: i=
67000
NOTE: i=
3810
NOTE: i=
381
NOTE: i=
3811
NOTE: i=
3819
NOTE: i=
382
NOTE: i=
383
NOTE: i=
99590
NOTE: i=
99591

View solution in original post


All Replies
Super User
Posts: 17,760

Re: Character values for index variable being converted to numeric

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;

Respected Advisor
Posts: 3,124

Re: Character values for index variable being converted to numeric

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

Solution
‎06-12-2014 03:39 PM
Respected Advisor
Posts: 3,777

Re: Character values for index variable being converted to numeric

I think the input data hcup.masterlong has numeric variable "I" causing the note.

data _null_;
   i=
1;
  
do i = '67000' , '03810' , '0381 ' , '03811' , '03819' , '0382 ' , '0383 ', '99590' , '99591';
     
put 'NOTE: ' i=;
      end;
  
run;

NOTE:
Character values have been converted to numeric values at the places given by: (Line)Smiley SadColumn).
     
18:11   18:21   18:31   18:41   18:51   18:61   18:71   18:80   18:90  
NOTE: i=
67000
NOTE: i=
3810
NOTE: i=
381
NOTE: i=
3811
NOTE: i=
3819
NOTE: i=
382
NOTE: i=
383
NOTE: i=
99590
NOTE: i=
99591
Respected Advisor
Posts: 3,124

Re: Character values for index variable being converted to numeric

This must be it!

New Contributor
Posts: 2

Re: Character values for index variable being converted to numeric

Yes, that was the problem. Thanks!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 398 views
  • 7 likes
  • 4 in conversation