- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Duplicates would not be allowed.
I tried it using the do loop and it worked the way I needed it to!
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.