How to read the value using array

Reply
Contributor
Posts: 32

How to read the value using array

Hi,

Could any one help me out ,

i do have a dataset like below

subjectRaceRace1Race2Race3Race4
101 Asian American
102chinese
103 African
104Asian AmericanAfrican
105 American

and and final dataset to be like below by using array if subject has one race then final variable must have that race if subject has more than one race then final variable must be Multiple

subjectRaceRace1Race2Race3Race4Final
101 Asian American Multiple
102chinese Chinese
103 African african
104Asian AmericanAfrican Multiple
105 American American
Super Contributor
Posts: 644

Re: How to read the value using array

Try this (untested)

Data want ;

     Set have ;

          Length final $ 32 ;

          Count = 5 - Cmiss (race, race1, race2, race3, race4) ;

          Select (Count) ;

               When (1)  Final = Cats (race, race1, race2, race3, race4) ;

               When (0)  Final =  ' ' ;

               Otherwise Final =  'Multiple' ;

          End ;

     Drop Count ;

Run ;

Richard

Contributor
Posts: 32

Re: How to read the value using array

Sorry it's not working and i want program by using array

Respected Advisor
Posts: 3,777

Re: How to read the value using array

Is this enough array usage to suit you.

data Race;
   array race[4] $12;
  
infile cards missover;
  
input subject:$3. Race
  • ;
  •    w = dim(race)-cmiss(of race
  • );
      
  • length final $12;
      
    select(w);
          when(1)  final = coalesceC(of race
  • );
  •       otherwise final = 'Multiple';
         
    end;
      
    cards;
    101 . Asian . American
    102 . . Chinese
    103 African
    104 Asian . American African
    105 . . American
    ;;;;
       run;
    proc print;
      
    run;
    Contributor
    Posts: 32

    Re: How to read the value using array

    Thank You DataNull but its not working because i m using Sas Version 9.0 so CMiss is not working

    and could you try another method and dont use cards methods just that dataset with set statement

    PROC Star
    Posts: 7,360

    Re: How to read the value using array

    You can replace the cards with whatever form of input you actually need.  You can get around using cmiss by using:

    data Race;

       array race[4] $12;

       infile cards missover;

       input subject:$3. Race

  • ;
  •    do i=1 to 4;

         if not missing(Race then w=w+1;

       end;

       length final $12;

       select(w);

          when(1)  final = coalesceC(of race

  • );
  •       otherwise final = 'Multiple';

          end;

       cards;

    101 . Asian . American

    102 . . Chinese

    103 African

    104 Asian . American African

    105 . . American

    ;;;;

       run;

    Contributor
    Posts: 32

    Re: How to read the value using array

    its not working

    error stating coalescec cannot be loaded

    Super User
    Super User
    Posts: 6,499

    Re: How to read the value using array

    If you have old version of SAS then you will need to use a more manual process.

    array race race1-race4 ;

    nonmiss=0;

    do over race;

      if race ne ' ' then do; nonmiss+1; final=race; end;

    end;

    if nonmiss > 1 then final='Multiple';

    Ask a Question
    Discussion stats
    • 7 replies
    • 278 views
    • 0 likes
    • 5 in conversation