BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AParriott
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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):(Column).
     
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

5 REPLIES 5
Reeza
Super User

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;

Haikuo
Onyx | Level 15

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

data_null__
Jade | Level 19

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):(Column).
     
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
AParriott
Calcite | Level 5

Yes, that was the problem. Thanks!

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!

How to connect to databases in SAS Viya

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.

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