LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2000, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 21 Mar 2000 11:27:27 -0500
Reply-To:     "Droogendyk, Harry" <Harry.Droogendyk@CIT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Droogendyk, Harry" <Harry.Droogendyk@CIT.COM>
Subject:      Re: Help with random assignment of values.
Content-Type: text/plain; charset="ISO-8859-1"

Richard:

Here's a program I've used to generate random values and also to select random values from an array:

Harry ======================================

libname harry 'c:\c_0302';

proc datasets library=work; delete test; run;

data test (keep=product region amt rptdate);

p1 = 'GIC'; p2 = 'Mortgage'; p3 = 'RESP'; p4 = 'RSP'; p5 = 'Savings'; p6 = 'Chequing';

r1 = 'BC'; r2 = 'AB'; r3 = 'SK'; r4 = 'MN'; r5 = 'ON'; r6 = 'PQ'; r7 = 'NS'; r8 = 'NB'; r9 = 'PEI'; r10 = 'NF';

array prods (6) p1-p6; array regions (10) r1-r10;

length product $15 region $3 day month 3. year 4. ;

label product = 'Product' region = 'Region' rptdate = 'Reporting*Date' amt = 'Amount' ;

format rptdate date9. amt 12.2 ;

do i=1 to 1000;

random = ranuni(i)*1000000000; product = prods(int(mod(random,6)) + 1); region = regions(int(mod(random,10)) + 1);

day = int(mod(random,31)) + 1; month = int(mod(random,12)) + 1; year = 1990 + int(mod(random,9)) + 1;

if month not in (1 3 5 7 8 10 12) then do; if month = 2 then do; if year = (int(year/4) * 4) then maxdays = 29; else maxdays = 28; end; else do; maxdays = 30; end; if day > maxdays then day = maxdays; end;

date = compress(month || '-' || day || '-' || year); rptdate = input(date,mmddyy10.);

amt = ranuni(i) * 100000;

output;

end;

run;

proc freq

data=test;

tables product region

/nopercent nocum ; run;

proc univariate data=test plot normal; run;

-----Original Message----- From: Walker, Richard M [mailto:Richard.M.Walker@BRITISHAIRWAYS.COM] Sent: Tuesday, March 21, 2000 10:58 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Help with random assignment of values.

SAS-Lers

I have a requirement to generate a SAS dataset for testing an update process.

I am looking to generate a data step that will create say, 100,000 records with a variable containing a random number and a number of variables containing a value that is randomly selected from a small group

CID LTYPRCD

random number 'EB','ES','EG','CB','CS','CG'

I can manage the generation of the random CID but I'm not sure how to randomly select a value for the LTYPRCD from the group indicated above.

Any guidance would be appreciated.

Regards Richard


Back to: Top of message | Previous page | Main SAS-L page