Hi, I would like to create a list of 25 randomly generated numbers that start with the two letters "AB----" ex: AB14587, AB65899, AB36525, etc.
I looked into the RAND function, but can't seem to figure out how I would incorporate the "AB-" in there.
Any help would be much appreciated!
Modifying @PeterClemmensen solution very slightly to use Z5 format so that you always have a string of the same length.
data want(drop=i);
length num $20;
do i=1 to 25;
num=cats("AB", put(rand('integer', 1, 10000), z5.));
output;
end;
run;
You could combine the output from this link with what you already have for the numeric portion: http://support.sas.com/kb/51/386.html
This would be combining 2 random elements: the text and the numbers.
Register today and join us virtually on June 16!
sasglobalforum.com | #SASGF
View now: on-demand content for SAS users
Do something like this
data want(drop=i);
length num $20;
do i=1 to 25;
num=cats("AB", rand('integer', 100, 10000));
output;
end;
run;
Modifying @PeterClemmensen solution very slightly to use Z5 format so that you always have a string of the same length.
data want(drop=i);
length num $20;
do i=1 to 25;
num=cats("AB", put(rand('integer', 1, 10000), z5.));
output;
end;
run;
@kmardinian wrote:
Hi, I would like to create a list of 25 randomly generated numbers that start with the two letters "AB----" ex: AB14587, AB65899, AB36525, etc.
I looked into the RAND function, but can't seem to figure out how I would incorporate the "AB-" in there.
Any help would be much appreciated!
Being a bit pedantic but unless AB are HEX digits then you are NOT generating random "numbers".
If you cast the question as "I would like to create a string value that starts with AB- followed by a random number" you might even have figured it out yourself.
Is there a specific range in the number of digits the number part must possess?
Duplicates would not be allowed.
I tried it using the do loop and it worked the way I needed it to!
Thank you!
@kmardinian wrote:
Duplicates would not be allowed.
I tried it using the do loop and it worked the way I needed it to!
Thank you!
My solution may generate duplicates.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.