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;

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!

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.

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
  • 2 replies
  • 1608 views
  • 1 like
  • 3 in conversation