DATA Step, Macro, Functions and more

Creating all values between a beginning and ending value

Reply
New Contributor
Posts: 3

Creating all values between a beginning and ending value

How would I go about creating a file with all the values between a begining and ending value. An example would be Beginning=AAA000 and Ending=CDE999.
N/A
Posts: 0

Re: Creating all values between a beginning and ending value

This is a very open ended question.

1) SAS Dataset "file" or text or binary? Mainframe?
2) each textual value (base 36) or hex numeric values (base 16)?

[pre]
data outdata;
do i=1 to 1000 by 10;
output;
end;
run;
quit;
[/pre]

Perhaps it would be of benefit for you to read some Base/SAS documentation.
New Contributor
Posts: 3

Re: Creating all values between a beginning and ending value

This is a mainframe "text" file, but I would think that any platform would act the same. The problem I'm having is that after AAA999 the next value should be ABA000. I've tried several times to get by the alphas but SAS always seems to want numerics only in the do loops.
Frequent Contributor
Posts: 139

Re: Creating all values between a beginning and ending value

Jim

By using temporary arrays you can do what you want. A temporary array creates a set of values without creating variables. As with all arrays you can loop through them. See the online doc for details http://support.sas.com/onlinedoc/913/docMainpage.jsp

My strategy was to look at your string as a collection of 6 one position characters. Then build upon that framework to get what you want.

My first exampe creates is the general case. The second example should solve you specific problem. Also my indention didn't make it while i copy/paste the code.


* General;
data One;

/* strategy, create a temporary array with all alphas and loop through to get all posible values */
array Alphas (26) $ 1 _temporary_ ('A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z');

do p1=1 to 26; /* Position 1 of the string being created */
do p2=1 to 26; /* Position 2 of the string being created */
do p3=1 to 26; /* Position 3 of the string being created */
do p4=0 to 999; /* Position 4-6 of the string being created, fortunately creating numbers is easy with SAS formats */
char=alphas[p1]||alphas[p2]||alphas[p3]; /* || = concatenation */
num=put(p4,z3.); /* converts the value of p4 into a text string with leading zeros */
Value=char||num;
output;

end;
end;
end;
end;



run;

** Specific Problem;
data Two;

array Alphas (26) $ 1 _temporary_ ('A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z');

do p1=1 to 3; /* Position 1 of the string being created, stops at C */
do p2=1 to 4; /* Position 2 of the string being created, stops at D */
do p3=1 to 5; /* Position 3 of the string being created, stops at R */
do p4=0 to 999; /* Position 4-6 of the string being created */
char=alphas[p1]||alphas[p2]||alphas[p3];
num=put(p4,z3.);
Value=char||num;
output;

end;
end;
end;
end;

run;

-Darryl
New Contributor
Posts: 3

Re: Creating all values between a beginning and ending value

darryl,

Thanks, just what the doctor ordered. It fine exactly as I needed.

Jim P
Ask a Question
Discussion stats
  • 4 replies
  • 132 views
  • 0 likes
  • 3 in conversation