BookmarkSubscribeRSS Feed
GemmaR
SAS Employee
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!
6 REPLIES 6
data_null__
Jade | Level 19
Perhaps if you make an array then use

[pre]
notMissing = dim(array)-cmiss(of array
  • );
    [/pre]
  • GemmaR
    SAS Employee
    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.......
    data_null__
    Jade | Level 19
    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.
  • Peter_C
    Rhodochrosite | Level 12
    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:
    Cynthia_sas
    Diamond | Level 26
    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
    GemmaR
    SAS Employee
    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.

    hackathon24-white-horiz.png

    The 2025 SAS Hackathon Kicks Off on June 11!

    Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

    YouTube LinkedIn

    How to Concatenate Values

    Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

    Find more tutorials on the SAS Users YouTube channel.

    SAS Training: Just a Click Away

     Ready to level-up your skills? Choose your own adventure.

    Browse our catalog!

    Discussion stats
    • 6 replies
    • 4802 views
    • 0 likes
    • 4 in conversation