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

I have a dataset containing 20 User Logins. (Only Var = Login)

 

I have 2 other datasets each containing 1 var.

PWSource1 contains 50 freshly prepared Passwords in a var called PW1.

PWSource2 contains about 90 other freshly prepared Passwords in a Var called PW2.

 

I need to select the Login from UserLogins (in=a) and then a random passw from PWSource1 (from PW1) and a second random password from PWSource2. 

For each Login I will combine PW1 and PW2 to make a single Password in my final output.

 

Has anyone got some sample code or suggestions on how to code the random selection of each Password per Login?

Any help will be much appreciated...

🙂

 

Len

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

To add some detail to @BrunoMueller suggestion:

 

data want;

set users;

recno = ceil(n_pw1 * ranuni(12345));

set pw1 nobs=n_pw1 point=recno;

recno = ceil(n_pw2 * ranuni(97531));

set pw1 nobs=n_pw2 point=recno;

run;

 

 

View solution in original post

7 REPLIES 7
BrunoMueller
SAS Super FREQ

You can use the POINT= options of the SET statement to randomly read an observation. To calculate the random observation number you can use the RANUNI function together with the CEIL function.

 

The NOBS= option on the SET statement will return the total number of observations in SAS data set.

 

The DATA step will read the data set with all the logins, you then calculate a random number to read from the password data set

Astounding
PROC Star

To add some detail to @BrunoMueller suggestion:

 

data want;

set users;

recno = ceil(n_pw1 * ranuni(12345));

set pw1 nobs=n_pw1 point=recno;

recno = ceil(n_pw2 * ranuni(97531));

set pw1 nobs=n_pw2 point=recno;

run;

 

 

Lenvdb
Quartz | Level 8
Thank you Astounding! this is perfect. much appreciated
Astounding
PROC Star

It takes a slightly different approach to make sure passwords are not reused.

 

proc sql noprint;

create table password_list as select * from pw1, pw2;

quit;

data password_list2;

set password_list;

random_order = ranuni(12345);

run;

proc sort data=password_list2;

by random_order;

run;

 

data want;

set users;

set password_list2 (drop=random_order);

run;

 

The solution from @PGStats may be successful.  It will limit the number of passwords that can be assigned to 50 (the smaller number from the PW1 and PW2 data sets).

Reeza
Super User

Can the passwords be reused?

Lenvdb
Quartz | Level 8

Hi Reeza

 

Passwords can be reused, but each combination of PW1 + PW2 should be unique:

 

A + M = AM  >> OK

A + N = AN  >> OK

 

B + M = BM >> OK

C + N = CN >> OK

 

A + M = AM >> Not OK as it is already used

PGStats
Opal | Level 21

If you want to make sure that the passwords are not reused then you could use this method:

 

data rLogins;
set logins;
rnd = rand("UNIFORM");
run;

data rPW1;
set PW1;
rnd = rand("UNIFORM");
run;

data rPW2;
set PW2;
rnd = rand("UNIFORM");
run;

proc sort data=rLogins; by rnd; run;
proc sort data=rPW1; by rnd; run;
proc sort data=rPW2; by rnd; run;

data want;
set rLogins;
set rPW1;
set rPW2;
run;
PG

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 921 views
  • 2 likes
  • 5 in conversation