BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
littlestone
Fluorite | Level 6

Suppose I have following codes:

data new;

set old;

array old_var_array

  • _CHARACTER_;
  • ..................(codes to be inserted)

    ..................(codes to be inserted)

    ..................(codes to be inserted)

    ..................(codes to be inserted)

    ..................

    ..................

    Based on number of character variables ( which can be obtained using dim(old_var_array) in the above example), I want to create equal number of new variables (NewVar1-NewVar#ofChar). How can I do this? thanks.

    1 ACCEPTED SOLUTION

    Accepted Solutions
    6 REPLIES 6
    art297
    Opal | Level 21

    Take a look at the method I suggested in a post the other day:

    http://communities.sas.com/message/104323#104323

    littlestone
    Fluorite | Level 6

    Thank you very much.The code you gave to me works perfectly for me

    By the way, I find another way that can also do the job. Here is the code (I am not sure if this method is considered professional or not):

    data _Null_;

    set old;

    array stringvar

  • _CHARACTER_;
  • NumofCVar = dim(stringvar) ;

    call SYMPUTX('NumOfCVar',NumOfCVar);

    run;

    data new;

    set old;

    array old_var_array

  • _CHARACTER_;
  • array _NewVar[&NumofCVar] NewVar1-NewVar&NumofCVar;

    ..............

    art297
    Opal | Level 21

    Looks almost sufficiently professional enough to me for whatever that is worth.  However, I would simplify the first step so that you don't read through all of the records.  e.g.:

    data _Null_;

      set have;

      if _n_ eq 1 then do;

        array stringvar

  • _CHARACTER_;
  •     NumofCVar = dim(stringvar) ;

        call SYMPUTX('NumOfCVar',NumOfCVar);

      end;

      stop;

    run;

    littlestone
    Fluorite | Level 6

    thanks a lot for suggestion

    Ksharp
    Super User

    dictionary tables already contains the number of character variables.

    proc sql ;

    select num_character

      from dictionary.tables

       where libname='SASHELP' and memname='CLASS';

    quit;

    Ksharp

    littlestone
    Fluorite | Level 6

    thank you Ksharp. I actually didn't know there exists "dictionary tables". It is such a wonderful tool.

    Catch up on SAS Innovate 2026

    Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

    Explore 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
    • 6 replies
    • 2997 views
    • 6 likes
    • 3 in conversation