BookmarkSubscribeRSS Feed
JimP
Calcite | Level 5
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.
4 REPLIES 4
deleted_user
Not applicable
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.
JimP
Calcite | Level 5
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.
darrylovia
Quartz | Level 8
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
JimP
Calcite | Level 5
darryl,

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

Jim P

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1006 views
  • 0 likes
  • 3 in conversation