Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
SAS - How to generate a random number between 1 and n
Goto page Previous  1, 2
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics
View previous topic :: :: View next topic  
Author Message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8491
Location: Dubuque, Iowa, USA

PostPosted: Fri Nov 02, 2012 7:50 pm    Post subject:
Reply with quote

If you put multiple values in SEEDFILE in the last code I posted, SAS will read each one and generate a random number. Do you need to be able to write each of these random numbers to an output file as well?
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19254
Location: Inside the Matrix

PostPosted: Fri Nov 02, 2012 8:45 pm    Post subject: Reply to: SAS - How to generate a random number between 1 an
Reply with quote

My bad icon_redface.gif
Yup, i've successfully run multiple input records.

However, I need to break out fields on the same input record(s). The value(s) will not always be in position 1.

So far, i've been able to find/use a numeric value that is not in position 1 (@nnn).

Also needed is a way to generate the random number without the leading zeros suppressed icon_confused.gif

'Preciate it!

d
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8491
Location: Dubuque, Iowa, USA

PostPosted: Fri Nov 02, 2012 9:29 pm    Post subject:
Reply with quote

Using a trailing @@ on the INPUT line such as
Code:
     INPUT SEEDVAL  @@ ;
will cause SAS to start looking for the second value immediately after the end of the first value. Make sure you do NOT have line numbers in your file, though, or the line numbers will be read as data.

Using a Zn. format for the PUT statement will cause SAS to add leading zeroes. If you want the value to be 8 digits wide, for example, use
Code:
PUT RANVAL Z8. ;
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19254
Location: Inside the Matrix

PostPosted: Fri Nov 02, 2012 10:24 pm    Post subject: Reply to: SAS - How to generate a random number between 1 an
Reply with quote

Excellent - the Zn. did the trick!

Once again, thanks very much.

d
Back to top
View user's profile Send private message
Charles Wolters

New User


Joined: 30 Mar 2011
Posts: 48
Location: United States

PostPosted: Thu Nov 15, 2012 1:33 am    Post subject: Reply to: SAS - How to generate a random number between 1 an
Reply with quote

Dick,

I have used the following approach where BOUND is your N value so here I want to select a random number between 1 and 25. Using the PARM keyword I am feeding the value of BOUND to SAS. The RANUNI function activates the SAS random number generator. The value of 959078 is the seed I have given to random number generator and this is arbitrary. The random number is written to the SAS log and I am not sure this is where you want it.

Charles Wolters

//S688CLWX JOB XXXUNKA9,S688CLW,
// MSGCLASS=R,NOTIFY=&SYSUID
// SET BOUND=25
//STEP1 EXEC SAS,PARM='SYSPARM="&BOUND"'
//SYSIN DD *
***PASS INTERVAL FOR RANDOM NUMBER GENERATION ;
DATA _NULL_ ;
RANNUM = INT(&SYSPARM * RANUNI(959078)) + 1 ;
CALL SYMPUT('MYNUM',PUT(RANNUM,8.)) ;
RUN ;
%PUT SELECTED RANDOM NUMBER = &MYNUM ;
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19254
Location: Inside the Matrix

PostPosted: Thu Nov 15, 2012 2:17 am    Post subject:
Reply with quote

Hi Charles,

Thanks for the reply icon_smile.gif

The following is what i (thanks to the suppport from Robert and Vasanth) have running now:
Code:
DATA SEEDFILE;                                       
     INFILE SEEDFILE;                                 
     INPUT @014 SEEDVAL;                             
     SEED = INT(MOD (TIME(), SUBSTR(SEEDVAL,1)+0)) ; 
     RANVAL = INT(RANUNI(SEED)*SEEDVAL) + 1 ;         
     FILE RANOUT;                                     
     PUT ' RANDACT  ' RANVAL Z7. ; 

This does not use the "parm" but rather an input file and the random number is written to the RANOUT DD statement.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics All times are GMT + 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts recursive SQL to generate list jzhardy DB2 3 Sun Apr 07, 2019 8:38 am
No new posts count the number of records from diff... janmejay CA Products 4 Mon Mar 25, 2019 11:29 pm
No new posts Add week number to a file name or rep... tejdeep0274 JCL & VSAM 2 Thu Jan 03, 2019 6:49 am
No new posts How to count the number of times key ... vnktrrd DFSORT/ICETOOL 14 Thu Nov 15, 2018 9:19 pm
No new posts Accessing control blocks to retrieve ... menonkiran COBOL Programming 5 Wed Nov 14, 2018 9:08 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us