BookmarkSubscribeRSS Feed
DakotaBison
Calcite | Level 5

Hi all,

I am trying to generate a table with 100 observations, one variable. This is a discrete variable with 4 levels so I used this code below and everything is fine.

data BMI (drop = i) ;

     array prob [4]    (0.01, 0.1, 0.26, 0.63);

     call streaminit(1234);

    

     do i = 1 to 100;

          BMI = rand("Table", of prob

  • );
  •      output;

    end;

    run;

    quit;

    However, what I really want is this to store the proportions (0.01, 0.1, 0.26, 0.63) in a matrix variable z, like this below, and then pass that matrix variable via array, prob

  • into the rand function, as shown below.
  • proc iml;

      use CHIS.RBMI_Freq;

      read all var {PERCENT} into XBMI ;

      Z = ((XBMI[1:4,])*.01);

    print Z;

    run;

    data BMI (drop = i) ;

         array prob

  •    Z ;
  •      call streaminit(1234);

        

         do i = 1 to 100;

              BMI = rand("Table", of prob

  • );
  •      output;

    end;

    run;

    quit;

    When I do this I get an error   Argument 2 to function RAND('Table',.) at line 822 column 15 is invalid.

    I need help. Thanks in advance.

    1 REPLY 1
    ballardw
    Super User

    I don't work much with IML but I would think you could do that as a row operation in IML. Data steo is, as error says, not going to accept that syntax the way you want as Z as called will create a single variable Z which is missing.I don't know if you could instead of Print Z create a macro variable in a format that looks like the values in the first example.

    BTW if you don't want to keep adding Drop i statements use Do _i_= for your loops. The paired underscores tell SAS to treat as a temporary variable and it is automatically dropped from the output.

    sas-innovate-2024.png

    Don't miss out on SAS Innovate - Register now for the FREE Livestream!

    Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

     

    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.

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