BookmarkSubscribeRSS Feed
Filipvdr
Pyrite | Level 9
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?
1 REPLY 1
data_null__
Jade | Level 19
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.
  • sas-innovate-2026-white.png



    April 27 – 30 | Gaylord Texan | Grapevine, Texas

    Registration is open

    Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
    Register now and lock in 2025 pricing—just $495!

    Register now

    What is Bayesian Analysis?

    Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

    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
    • 1 reply
    • 1003 views
    • 0 likes
    • 2 in conversation