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
    SAS Super FREQ
    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.

    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 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.

    Click image to register for webinarClick image to register for webinar

    Classroom Training Available!

    Select SAS Training centers are offering in-person courses. View upcoming courses for:

    View all other training opportunities.

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