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

So I am creating a scoring Macro for a questionnaire while I wait for my data to arrive. 

 

I would like to create a dataset to test out the scoring macro that I have created. 

 

Basically, the dataset would be ID  (1,2,3,4) and Var1-var30, where Var1-30 have randomly generated whole number values between 1 and 6. Also I would like to have a seed to start so I can replicate the same dataset again.  I need maybe 10 records at most. 

 

I did some quick googling and can't seem to figure this out. The rand function I found seem to come up with numbers with decimal values (which is not what I want, I want whole numbers 1,2,3,4,5 or 6).  I think this should be a basic task but I can't seem to figure it out 😞 So I am hoping someone can help me

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Low seeds generate approximately random numbers, but that's probably all you will need for test data. 

 

data want;

array var {30};

do obsno=1 to 10;

   id = ceil(ranuni(12345) * 4);

   do seed=1 to 30;

      var{seed} = ceil(ranuni(seed) * 6);

   end;

   output;

end;

run;

View solution in original post

2 REPLIES 2
ballardw
Super User

See if this gives you a start.

 



data want;
   array v var1-var30;
   call streaminit (123); /* this makes the random results reproducable*/
   do id=1 to 10;
      do i=1 to dim(v);
         /* the decimal values refer to the proportion of responses that should have
            the order value. ('table', .4, .3, .2, .1) would have 40% with value 1, 
            30% with 2, 20% with 3 and 10% with 1.. The values should total to 1.
            adjust as desired
            The following line says each of the varaibles with have the same overall
            distribution but the values per individual record will vary.
            If you want to have different distributions than you could have 
            single line per var and skip the i loop for array, OR have multiple 
            arrays each group with a similar distribution 
         */
         v[i]= rand('table', .25, .15, .18, .12, .2, .1); 
         
      end;
      output;
   end;
   drop i;
run;
Astounding
PROC Star

Low seeds generate approximately random numbers, but that's probably all you will need for test data. 

 

data want;

array var {30};

do obsno=1 to 10;

   id = ceil(ranuni(12345) * 4);

   do seed=1 to 30;

      var{seed} = ceil(ranuni(seed) * 6);

   end;

   output;

end;

run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2486 views
  • 1 like
  • 3 in conversation