DATA Step, Macro, Functions and more

Counting non-missing character variables.

Reply
SAS Employee
Posts: 151

Counting non-missing character variables.

Hi All,

I am trying to use a dataset to count the occurances of non missing values within a dynamic list of character variables.

Is there a function that I can't find on help such as CMISS but that counts non missing instead?

Thanks in advance for any advice!
Respected Advisor
Posts: 3,777

Re: Counting non-missing character variables.

Perhaps if you make an array then use

[pre]
notMissing = dim(array)-cmiss(of array
  • );
    [/pre]
  • SAS Employee
    Posts: 151

    Re: Counting non-missing character variables.

    Thanks for the suggestion data_null, it just needs to be even more simple than an array or a do loop as they don't know those. We are using EG and I just didn't know if there was a function I had missed along the way.......
    Respected Advisor
    Posts: 3,777

    Re: Counting non-missing character variables.

    There is no DO looping involved. I don't know EG but this seems pretty simple to me.

    [pre]
    data ...;
    set ...;
    array _c
  • _character_;
    notmissing = dim(_c) - cmiss(of _c
  • );
    run;
    [/pre]

    AFAIK you will need to define the array to determine the number of _character_ variables.
  • Valued Guide
    Posts: 2,175

    Re: Counting non-missing character variables.

    how dynamic is the list of character variables?
    Possibly could use the modifiers which provide more support for delimters.
    CATQ() and COUNTW(), as shown in this SASlog snippet :[pre]1625 %let dynamic_var_list = c a b ;
    1626 data ;
    1627 a='1'; b='|'; c=' ' ;
    1628 d= catq( 'mdt','|', of a c b );
    1629 put d= ;
    1630 e= countw( d, '|', 'mq' ) ;
    1631 f= countw( d, '|', 'q' ) ;
    1632 put e= f= ;
    1633 allasone= countW( catq( 'mdt','|', of &dynamic_var_list ), '|', 'q' ) ;
    1634 put (_all_)(=) ;
    1635 run;

    d=1||"|"
    e=3 f=2
    a=1 b=| c= d=1||"|" e=3 f=2 allasone=2
    NOTE:
    SAS Super FREQ
    Posts: 8,744

    Re: Counting non-missing character variables.

    Hi:
    Here's my .02 -- when I see "count" and "values", I automatically think of PROC FREQ. PROC FREQ can create an output dataset and it can take:
    TABLES _CHARACTER_;
    or TABLES &wantchar;

    in the syntax.

    You said you were trying to -use- a dataset to do the counting...I interpreted that as dataset going in, but ??? what's coming out ??? another dataset or a report??

    cynthia
    SAS Employee
    Posts: 151

    Re: Counting non-missing character variables.

    Hello there,

    Thanks for all the advice, am going to go with do-loops and arrays to output and count the information that I've got.
    Ask a Question
    Discussion stats
    • 6 replies
    • 524 views
    • 0 likes
    • 4 in conversation