Help using Base SAS procedures

counting objects divided by dashes and ;

Reply
Regular Contributor
Posts: 235

counting objects divided by dashes and ;

Hello

I have data like DO1;DO3;DO4-DO10;DO15;DO17;
So in total my number would be 11 (1,3,4,5,6,7,8,9,10,15,17)

Currently i have this:

Number = countc(DataField,';') + 1;

but I need the objects between DO4 and D010 as well.. any help?
Respected Advisor
Posts: 3,799

Re: counting objects divided by dashes and ;

Much depends on what your ultimate goal is. I personally don't like to think too hard. I see that that DATAFIELD looks like a SAS Variable List that can be used in a array statement. If I let SAS create an ARRAY with the list I can use DIM to determine the number of elements.

[pre]
431 data _null_;
432 dataField='DO1;DO3;DO4-DO10;DO15;DO17;';
433 call symputX('dataField',translate(datafield,' ',';'));
434 run;



435 %put NOTE: DATAFIELD=&datafield;
NOTE: DATAFIELD=DO1 DO3 DO4-DO10 DO15 DO17
436 data _null_;
437 array d
  • &datafield;
    438 call symputX('dim',dim(d));
    439 run;

    440 %put NOTE: DIM=&dim;
    NOTE: DIM=11
    [/pre]


    This concept can be extended to any "Variable List" using PROC TRANSPOSE.
  • Ask a Question
    Discussion stats
    • 1 reply
    • 127 views
    • 0 likes
    • 2 in conversation